Fork me on GitHub

Ignore:
Timestamp:
Oct 18, 2014, 12:27:15 PM (10 years ago)
Author:
Christophe Delaere <christophe.delaere@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
5fbcfe8
Parents:
400597a
Message:

Code reorganization

Moved the methods that read branches to the correponding BranchElements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • display/DelphesEventDisplay.cc

    r400597a r4fd37d4  
    5353   totRadius_ = 2.0;
    5454   tkHalfLength_ = 3.0;
     55   muHalfLength_ = 6.0;
    5556   bz_ = 3.8;
    5657   chain_ = new TChain("Delphes");
    5758   treeReader_ = 0;
    5859   delphesDisplay_ = 0;
     60   etaAxis_ = 0;
     61   phiAxis_ = 0;
    5962}
    6063
     
    8386   totRadius_ = det3D.getDetectorRadius();
    8487   tkHalfLength_ = det3D.getTrackerHalfLength();
     88   muHalfLength_ = det3D.getDetectorHalfLength();
    8589   bz_ = det3D.getBField();
     90   etaAxis_ = det3D.getCaloAxes().first;
     91   phiAxis_ = det3D.getCaloAxes().second;
    8692   TGeoVolume* top = det3D.getDetector(false);
    8793   geom->SetTopVolume(top);
     
    105111
    106112   // prepare data collections
    107    readConfig(configFile, det3D, elements_, arrays_);
     113   readConfig(configFile, elements_);
    108114   for(std::vector<DelphesBranchBase*>::iterator element = elements_.begin(); element<elements_.end(); ++element) {
    109115     DelphesBranchElement<TEveTrackList>*   item_v1 = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(*element);
     
    120126   // find the first calo data and use that to initialize the calo display
    121127   for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
    122      if(TString((*data)->GetType())=="tower") { // we could also use GetClassName()=="DelphesCaloData"
     128     if(TString((*data)->GetType())=="Tower") { // we could also use GetClassName()=="DelphesCaloData"
    123129       DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>((*data))->GetContainer();
    124130       assert(container);
     
    146152
    147153// function that parses the config to extract the branches of interest and prepare containers
    148 void DelphesEventDisplay::readConfig(const char *configFile, Delphes3DGeometry& det3D, std::vector<DelphesBranchBase*>& elements, std::vector<TClonesArray*>& arrays) {
     154void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase*>& elements) {
    149155   ExRootConfReader *confReader = new ExRootConfReader;
    150156   confReader->ReadFile(configFile);
    151    Double_t tk_radius = det3D.getTrackerRadius();
    152    Double_t tk_length = det3D.getTrackerHalfLength();
    153    Double_t tk_Bz     = det3D.getBField();
    154    Double_t mu_radius = det3D.getDetectorRadius();
    155    Double_t mu_length = det3D.getDetectorHalfLength();
    156    TAxis*   etaAxis   = det3D.getCaloAxes().first;
    157    TAxis*   phiAxis   = det3D.getCaloAxes().second;
    158157   ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
    159158   Int_t nBranches = branches.GetSize()/3;
     
    168167     if(className=="Tower") {
    169168       if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
    170        clist = new DelphesBranchElement<DelphesCaloData>(name,"tower",kBlack);
    171        clist->GetContainer()->SetEtaBins(etaAxis);
    172        clist->GetContainer()->SetPhiBins(phiAxis);
     169       clist = new DelphesBranchElement<DelphesCaloData>(name,treeReader_->UseBranch(name),kBlack);
     170       clist->GetContainer()->SetEtaBins(etaAxis_);
     171       clist->GetContainer()->SetPhiBins(phiAxis_);
    173172       elements.push_back(clist);
    174173     } else if(className=="Jet") {
    175174       if(input.Contains("GenJetFinder")) {
    176          elist = new DelphesBranchElement<TEveElementList>(name,"jet",kCyan);
     175         elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kCyan);
    177176         elist->GetContainer()->SetRnrSelf(false);
    178177         elist->GetContainer()->SetRnrChildren(false);
     178         elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    179179         elements.push_back(elist);
    180180       } else {
    181          elements.push_back(new DelphesBranchElement<TEveElementList>(name,"jet",kYellow));
     181         elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kYellow);
     182         elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     183         elements.push_back(elist);
    182184       }
    183185     } else if(className=="Electron") {
    184        tlist = new DelphesBranchElement<TEveTrackList>(name,"electron",kRed);
    185        elements.push_back(tlist);
    186        TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
    187        trkProp->SetMagField(0., 0., -tk_Bz);
    188        trkProp->SetMaxR(tk_radius);
    189        trkProp->SetMaxZ(tk_length);
     186       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kRed);
     187       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     188       elements.push_back(tlist);
    190189     } else if(className=="Photon") {
    191        tlist = new DelphesBranchElement<TEveTrackList>(name,"photon",kYellow);
    192        elements.push_back(tlist);
    193        TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
    194        trkProp->SetMagField(0., 0., 0.);
    195        trkProp->SetMaxR(tk_radius);
    196        trkProp->SetMaxZ(tk_length);
     190       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kYellow);
     191       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     192       elements.push_back(tlist);
    197193     } else if(className=="Muon") {
    198        tlist = new DelphesBranchElement<TEveTrackList>(name,"muon",kGreen);
    199        elements.push_back(tlist);
    200        TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
    201        trkProp->SetMagField(0., 0., -tk_Bz);
    202        trkProp->SetMaxR(mu_radius);
    203        trkProp->SetMaxZ(mu_length);
     194       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kGreen);
     195       tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
     196       elements.push_back(tlist);
    204197     } else if(className=="MissingET") {
    205        elements.push_back(new DelphesBranchElement<TEveElementList>(name,"vector",kViolet));
     198       elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kViolet);
     199       elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     200       elements.push_back(elist);
    206201     } else if(className=="GenParticle") {
    207        tlist = new DelphesBranchElement<TEveTrackList>(name,"genparticle",kCyan);
    208        elements.push_back(tlist);
     202       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kCyan);
     203       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    209204       tlist->GetContainer()->SetRnrSelf(false);
    210205       tlist->GetContainer()->SetRnrChildren(false);
    211        TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
    212        trkProp->SetMagField(0., 0., -tk_Bz);
    213        trkProp->SetMaxR(tk_radius);
    214        trkProp->SetMaxZ(tk_length);
     206       elements.push_back(tlist);
    215207     } else {
    216208       continue;
    217209     }
    218      arrays.push_back(treeReader_->UseBranch(name));
    219210   }
    220211   // second loop for tracks
     
    225216     if(className=="Track") {
    226217       if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
    227        tlist = new DelphesBranchElement<TEveTrackList>(name,"track",kBlue);
    228        elements.push_back(tlist);
    229        TEveTrackPropagator *trkProp = tlist->GetContainer()->GetPropagator();
    230        trkProp->SetMagField(0., 0., -tk_Bz);
    231        trkProp->SetMaxR(tk_radius);
    232        trkProp->SetMaxZ(tk_length);
    233        arrays.push_back(treeReader_->UseBranch(name));
     218       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kBlue);
     219       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     220       elements.push_back(tlist);
    234221     }
    235222   }
     
    255242   // Load selected branches with data from specified event
    256243   treeReader_->ReadEntry(event_id_);
    257 
    258    // loop over selected branches, and apply the proper recipe to fill the collections.
    259    // this is basically to loop on arrays_ to fill elements_.
    260    std::vector<TClonesArray*>::iterator data = arrays_.begin();
    261    std::vector<DelphesBranchBase*>::iterator element = elements_.begin();
    262    for(; data<arrays_.end() && element<elements_.end(); ++data, ++element) {
    263      TString type = (*element)->GetType();
    264      // branch on the element type
    265      if(type=="tower") delphes_read_towers(*data,*element);
    266      else if(type=="track" || type=="photon" || type=="electron" || type=="muon" || type=="genparticle") delphes_read_tracks(*data,*element);
    267      else if(type=="jet") delphes_read_jets(*data,*element);
    268      else if(type=="vector") delphes_read_vectors(*data,*element);
     244   for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
     245     (*data)->ReadBranch();
    269246   }
    270247
     
    278255
    279256   gEve->Redraw3D(kFALSE, kTRUE);
    280 }
    281 
    282 void DelphesEventDisplay::delphes_read_towers(TClonesArray* data, DelphesBranchBase* element) {
    283   DelphesCaloData* container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>(element)->GetContainer();
    284   assert(container);
    285   // Loop over all towers
    286   TIter itTower(data);
    287   Tower *tower;
    288   while((tower = (Tower *) itTower.Next()))
    289   {
    290     container->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]);
    291     container->FillSlice(0, tower->Eem);
    292     container->FillSlice(1, tower->Ehad);
    293   }
    294   container->DataChanged();
    295 }
    296 
    297 void DelphesEventDisplay::delphes_read_tracks(TClonesArray* data, DelphesBranchBase* element) {
    298   TEveTrackList* container = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(element)->GetContainer();
    299   assert(container);
    300   TString type = element->GetType();
    301   TIter itTrack(data);
    302   Int_t counter = 0;
    303   TEveTrack *eveTrack;
    304   TEveTrackPropagator *trkProp = container->GetPropagator();
    305   if(type=="track") {
    306     // Loop over all tracks
    307     Track *track;
    308     while((track = (Track *) itTrack.Next())) {
    309       TParticle pb(track->PID, 1, 0, 0, 0, 0,
    310                    track->P4().Px(), track->P4().Py(),
    311                    track->P4().Pz(), track->P4().E(),
    312                    track->X, track->Y, track->Z, 0.0);
    313       eveTrack = new TEveTrack(&pb, counter, trkProp);
    314       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
    315       eveTrack->SetStdTitle();
    316       eveTrack->SetAttLineAttMarker(container);
    317       container->AddElement(eveTrack);
    318       eveTrack->SetLineColor(element->GetColor());
    319       eveTrack->MakeTrack();
    320     }
    321   } else if(type=="electron") {
    322     // Loop over all electrons
    323     Electron *electron;
    324     while((electron = (Electron *) itTrack.Next())) {
    325       TParticle pb(electron->Charge<0?11:-11, 1, 0, 0, 0, 0,
    326                    electron->P4().Px(), electron->P4().Py(),
    327                    electron->P4().Pz(), electron->P4().E(),
    328                    0., 0., 0., 0.);
    329 
    330       eveTrack = new TEveTrack(&pb, counter, trkProp);
    331       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
    332       eveTrack->SetStdTitle();
    333       eveTrack->SetAttLineAttMarker(container);
    334       container->AddElement(eveTrack);
    335       eveTrack->SetLineColor(element->GetColor());
    336       eveTrack->MakeTrack();
    337     }
    338   } else if(type=="muon") {
    339     // Loop over all muons
    340     Muon *muon;
    341     while((muon = (Muon *) itTrack.Next())) {
    342       TParticle pb(muon->Charge<0?13:-13, 1, 0, 0, 0, 0,
    343                    muon->P4().Px(), muon->P4().Py(),
    344                    muon->P4().Pz(), muon->P4().E(),
    345                    0., 0., 0., 0.);
    346 
    347       eveTrack = new TEveTrack(&pb, counter, trkProp);
    348       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
    349       eveTrack->SetStdTitle();
    350       eveTrack->SetAttLineAttMarker(container);
    351       container->AddElement(eveTrack);
    352       eveTrack->SetLineColor(element->GetColor());
    353       eveTrack->MakeTrack();
    354     }
    355   } else if(type=="photon") {
    356     // Loop over all photons
    357     Photon *photon;
    358     while((photon = (Photon *) itTrack.Next())) {
    359       TParticle pb(22, 1, 0, 0, 0, 0,
    360                    photon->P4().Px(), photon->P4().Py(),
    361                    photon->P4().Pz(), photon->P4().E(),
    362                    0., 0., 0., 0.);
    363       eveTrack = new TEveTrack(&pb, counter, trkProp);
    364       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
    365       eveTrack->SetStdTitle();
    366       eveTrack->SetAttLineAttMarker(container);
    367       eveTrack->SetLineStyle(7);
    368       container->AddElement(eveTrack);
    369       eveTrack->SetLineColor(element->GetColor());
    370       eveTrack->MakeTrack();
    371     }
    372   } else if(type=="genparticle") {
    373     // Loop over all particles
    374     GenParticle *particle;
    375     while((particle = (GenParticle *) itTrack.Next())) {
    376       TParticle pb(particle->PID, particle->Status, particle->M1, particle->M2, particle->D1, particle->D2,
    377                    particle->P4().Px(), particle->P4().Py(),
    378                    particle->P4().Pz(), particle->P4().E(),
    379                    particle->X, particle->Y, particle->Z, particle->T);
    380       eveTrack = new TEveTrack(&pb, counter, trkProp);
    381       eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
    382       eveTrack->SetStdTitle();
    383       eveTrack->SetAttLineAttMarker(container);
    384       container->AddElement(eveTrack);
    385       eveTrack->SetLineColor(element->GetColor());
    386       if(particle->Charge==0) eveTrack->SetLineStyle(7);
    387       eveTrack->MakeTrack();
    388     }
    389   }
    390 }
    391 
    392 void DelphesEventDisplay::delphes_read_jets(TClonesArray* data, DelphesBranchBase* element) {
    393   TEveElementList* container = dynamic_cast<DelphesBranchElement<TEveElementList>*>(element)->GetContainer();
    394   assert(container);
    395   TIter itJet(data);
    396   Jet *jet;
    397   TEveJetCone *eveJetCone;
    398   // Loop over all jets
    399   Int_t counter = 0;
    400   while((jet = (Jet *) itJet.Next()))
    401   {
    402     eveJetCone = new TEveJetCone();
    403     eveJetCone->SetTitle(Form("jet [%d]: Pt=%f, Eta=%f, \nPhi=%f, M=%f",counter,jet->PT, jet->Eta, jet->Phi, jet->Mass));
    404     eveJetCone->SetName(Form("jet [%d]", counter++));
    405     eveJetCone->SetMainTransparency(60);
    406     eveJetCone->SetLineColor(element->GetColor());
    407     eveJetCone->SetFillColor(element->GetColor());
    408     eveJetCone->SetCylinder(tkRadius_ - 10, tkHalfLength_ - 10);
    409     eveJetCone->SetPickable(kTRUE);
    410     eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi);
    411     container->AddElement(eveJetCone);
    412   }
    413 }
    414 
    415 void DelphesEventDisplay::delphes_read_vectors(TClonesArray* data, DelphesBranchBase* element) {
    416   TEveElementList* container = dynamic_cast<DelphesBranchElement<TEveElementList>*>(element)->GetContainer();
    417   assert(container);
    418   TIter itMet(data);
    419   MissingET *MET;
    420   TEveArrow *eveMet;
    421   // Missing Et
    422   Double_t maxPt = 50.;
    423   // TODO to be changed as we don't have access to maxPt anymore. MET scale could be a general parameter set in GUI
    424   while((MET = (MissingET*) itMet.Next())) {
    425     eveMet = new TEveArrow((tkRadius_ * MET->MET/maxPt)*cos(MET->Phi), (tkRadius_ * MET->MET/maxPt)*sin(MET->Phi), 0., 0., 0., 0.);
    426     eveMet->SetMainColor(element->GetColor());
    427     eveMet->SetTubeR(0.04);
    428     eveMet->SetConeR(0.08);
    429     eveMet->SetConeL(0.10);
    430     eveMet->SetPickable(kTRUE);
    431     eveMet->SetName("Missing Et");
    432     eveMet->SetTitle(Form("Missing Et (%.1f GeV)",MET->MET));
    433     container->AddElement(eveMet);
    434   }
    435257}
    436258
Note: See TracChangeset for help on using the changeset viewer.