154 ClassImp(TGenerator);
 
  160 TGenerator::TGenerator(
const char *name,
const char *title): TNamed(name,title)
 
  163    TDatabasePDG::Instance();
 
  168    fShowNeutrons = kTRUE;
 
  169    fParticles    =  
new TObjArray(10000);
 
  176 TGenerator::~TGenerator()
 
  180       fParticles->Delete();
 
  189 void TGenerator::GenerateEvent()
 
  205 TObjArray* TGenerator::ImportParticles(Option_t *option)
 
  208    Int_t numpart = HEPEVT.nhep;
 
  209    if (!strcmp(option,
"") || !strcmp(option,
"Final")) {
 
  210       for (Int_t i = 0; i<numpart; i++) {
 
  211          if (HEPEVT.isthep[i] == 1) {
 
  215             TParticle *p = 
new TParticle(
 
  218                                    HEPEVT.jmohep[i][0]-1,
 
  219                                    HEPEVT.jmohep[i][1]-1,
 
  220                                    HEPEVT.jdahep[i][0]-1,
 
  221                                    HEPEVT.jdahep[i][1]-1,
 
  233    } 
else if (!strcmp(option,
"All")) {
 
  234       for (Int_t i = 0; i<numpart; i++) {
 
  235          TParticle *p = 
new TParticle(
 
  238                                    HEPEVT.jmohep[i][0]-1,
 
  239                                    HEPEVT.jmohep[i][1]-1,
 
  240                                    HEPEVT.jdahep[i][0]-1,
 
  241                                    HEPEVT.jdahep[i][1]-1,
 
  270 Int_t TGenerator::ImportParticles(TClonesArray *particles, Option_t *option)
 
  272    if (particles == 0) 
return 0;
 
  273    TClonesArray &clonesParticles = *particles;
 
  274    clonesParticles.Clear();
 
  275    Int_t numpart = HEPEVT.nhep;
 
  276    if (!strcmp(option,
"") || !strcmp(option,
"Final")) {
 
  277       for (Int_t i = 0; i<numpart; i++) {
 
  278          if (HEPEVT.isthep[i] == 1) {
 
  282             new(clonesParticles[i]) TParticle(
 
  285                                    HEPEVT.jmohep[i][0]-1,
 
  286                                    HEPEVT.jmohep[i][1]-1,
 
  287                                    HEPEVT.jdahep[i][0]-1,
 
  288                                    HEPEVT.jdahep[i][1]-1,
 
  299    } 
else if (!strcmp(option,
"All")) {
 
  300       for (Int_t i = 0; i<numpart; i++) {
 
  301          new(clonesParticles[i]) TParticle(
 
  304                                    HEPEVT.jmohep[i][0]-1,
 
  305                                    HEPEVT.jmohep[i][1]-1,
 
  306                                    HEPEVT.jdahep[i][0]-1,
 
  307                                    HEPEVT.jdahep[i][1]-1,
 
  324 void TGenerator::Browse(TBrowser *)
 
  334 Int_t TGenerator::DistancetoPrimitive(Int_t px, Int_t py)
 
  336    const Int_t big = 9999;
 
  337    const Int_t inview = 0;
 
  339    if (px > 50 && py > 50) dist = inview;
 
  348 void TGenerator::Draw(Option_t *option)
 
  352       gROOT->MakeDefCanvas();
 
  353       if (gPad->GetVirtCanvas())
 
  354          gPad->GetVirtCanvas()->SetFillColor(13);
 
  357    static Float_t rbox = 1000;
 
  358    Float_t rmin[3],rmax[3];
 
  359    TView *view = gPad->GetView();
 
  360    if (!strstr(option,
"same")) {
 
  361       if (view) { view->GetRange(rmin,rmax); rbox = rmax[2];}
 
  367    view = gPad->GetView();
 
  370       view->GetRange(rmin,rmax);
 
  373       view = TView::CreateView(1,0,0);
 
  374       if (view) view->SetRange(-rbox,-rbox,-rbox, rbox,rbox,rbox );
 
  376    const Int_t kColorProton    = 4;
 
  377    const Int_t kColorNeutron   = 5;
 
  378    const Int_t kColorAntiProton= 3;
 
  379    const Int_t kColorPionPlus  = 6;
 
  380    const Int_t kColorPionMinus = 2;
 
  381    const Int_t kColorKaons     = 7;
 
  382    const Int_t kColorElectrons = 0;
 
  383    const Int_t kColorGamma     = 18;
 
  387    Int_t nAntiProtons= 0;
 
  389    Int_t nPionMinus  = 0;
 
  391    Int_t nElectrons  = 0;
 
  394    Int_t ntracks = fParticles->GetEntriesFast();
 
  395    Int_t i,lwidth,color,lstyle;
 
  399    Double_t etot,vx,vy,vz;
 
  401    for (i=0;i<ntracks;i++) {
 
  402       p = (TParticle*)fParticles->UncheckedAt(i);
 
  404       ap = (TParticlePDG*)p->GetPDG();
 
  408       if  (vx*vx+vy*vy+vz*vz > rbox*rbox) 
continue;
 
  409       Float_t pt = p->Pt();
 
  410       if (pt < fPtCut) 
continue;
 
  412       if (etot > 0.1) lwidth = Int_t(6*TMath::Log10(etot));
 
  414       if (lwidth < 1) lwidth = 1;
 
  417       name = ap->GetName();
 
  418       if (!strcmp(name,
"n"))     { 
if (!fShowNeutrons) 
continue;
 
  419                                    color = kColorNeutron;    nNeutrons++;}
 
  420       if (!strcmp(name,
"p"))     { color = kColorProton;     nProtons++;}
 
  421       if (!strcmp(name,
"p bar")) { color = kColorAntiProton; nAntiProtons++;}
 
  422       if (!strcmp(name,
"pi+"))   { color = kColorPionPlus;   nPionPlus++;}
 
  423       if (!strcmp(name,
"pi-"))   { color = kColorPionMinus;  nPionMinus++;}
 
  424       if (!strcmp(name,
"e+"))    { color = kColorElectrons;  nElectrons++;}
 
  425       if (!strcmp(name,
"e-"))    { color = kColorElectrons;  nElectrons++;}
 
  426       if (!strcmp(name,
"gamma")) { color = kColorGamma;      nGammas++; lstyle = 3; }
 
  427       if ( strstr(name,
"K"))     { color = kColorKaons;      nKaons++;}
 
  428       p->SetLineColor(color);
 
  429       p->SetLineStyle(lstyle);
 
  430       p->SetLineWidth(lwidth);
 
  436    TPaveText *pt = 
new TPaveText(-0.94,0.85,-0.25,0.98,
"br");
 
  437    pt->AddText((
char*)GetName());
 
  438    pt->AddText((
char*)GetTitle());
 
  439    pt->SetFillColor(42);
 
  444    if (gPad->GetFillColor() == 10) tcolor = 4;
 
  445    TText *text = 
new TText(-0.95,-0.47,
"Particles");
 
  446    text->SetTextAlign(12);
 
  447    text->SetTextSize(0.025);
 
  448    text->SetTextColor(tcolor);
 
  450    text->SetTextColor(kColorGamma);      text->DrawText(-0.95,-0.52,
"(on screen)");
 
  451    text->SetTextColor(kColorGamma);      text->DrawText(-0.95,-0.57,
"Gamma");
 
  452    text->SetTextColor(kColorProton);     text->DrawText(-0.95,-0.62,
"Proton");
 
  453    text->SetTextColor(kColorNeutron);    text->DrawText(-0.95,-0.67,
"Neutron");
 
  454    text->SetTextColor(kColorAntiProton); text->DrawText(-0.95,-0.72,
"AntiProton");
 
  455    text->SetTextColor(kColorPionPlus);   text->DrawText(-0.95,-0.77,
"Pion +");
 
  456    text->SetTextColor(kColorPionMinus);  text->DrawText(-0.95,-0.82,
"Pion -");
 
  457    text->SetTextColor(kColorKaons);      text->DrawText(-0.95,-0.87,
"Kaons");
 
  458    text->SetTextColor(kColorElectrons);  text->DrawText(-0.95,-0.92,
"Electrons,etc.");
 
  460    text->SetTextColor(tcolor);
 
  461    text->SetTextAlign(32);
 
  463    snprintf(tcount,12,
"%d",ntracks);      text->DrawText(-0.55,-0.47,tcount);
 
  464    snprintf(tcount,12,
"%d",ninvol);       text->DrawText(-0.55,-0.52,tcount);
 
  465    snprintf(tcount,12,
"%d",nGammas);      text->DrawText(-0.55,-0.57,tcount);
 
  466    snprintf(tcount,12,
"%d",nProtons);     text->DrawText(-0.55,-0.62,tcount);
 
  467    snprintf(tcount,12,
"%d",nNeutrons);    text->DrawText(-0.55,-0.67,tcount);
 
  468    snprintf(tcount,12,
"%d",nAntiProtons); text->DrawText(-0.55,-0.72,tcount);
 
  469    snprintf(tcount,12,
"%d",nPionPlus);    text->DrawText(-0.55,-0.77,tcount);
 
  470    snprintf(tcount,12,
"%d",nPionMinus);   text->DrawText(-0.55,-0.82,tcount);
 
  471    snprintf(tcount,12,
"%d",nKaons);       text->DrawText(-0.55,-0.87,tcount);
 
  472    snprintf(tcount,12,
"%d",nElectrons);   text->DrawText(-0.55,-0.92,tcount);
 
  474    text->SetTextAlign(12);
 
  475    if (nPionPlus+nPionMinus) {
 
  476       snprintf(tcount,31,
"Protons/Pions= %4f",Float_t(nProtons)/Float_t(nPionPlus+nPionMinus));
 
  478       strlcpy(tcount,
"Protons/Pions= inf",31);
 
  480    text->DrawText(-0.45,-0.92,tcount);
 
  482    if (nPionPlus+nPionMinus) {
 
  483       snprintf(tcount,31,
"Kaons/Pions= %4f",Float_t(nKaons)/Float_t(nPionPlus+nPionMinus));
 
  485       strlcpy(tcount,
"Kaons/Pions= inf",31);
 
  487    text->DrawText(0.30,-0.92,tcount);
 
  495 void TGenerator::ExecuteEvent(Int_t event, Int_t px, Int_t py)
 
  497    if (gPad->GetView()) {
 
  498       gPad->GetView()->ExecuteRotateView(event, px, py);
 
  506 Int_t TGenerator::GetNumberOfParticles()
 const 
  508    return fParticles->GetLast()+1;
 
  515 TParticle *TGenerator::GetParticle(Int_t i)
 const 
  517    if (!fParticles) 
return 0;
 
  518    Int_t n = fParticles->GetLast();
 
  519    if (i < 0 || i > n) 
return 0;
 
  520    return (TParticle*)fParticles->UncheckedAt(i);
 
  528 void TGenerator::Paint(Option_t *)
 
  537 void TGenerator::SetPtCut(Float_t ptcut)
 
  549 void TGenerator::SetViewRadius(Float_t rbox)
 
  551    SetViewRange(-rbox,-rbox,-rbox,rbox,rbox,rbox);
 
  559 void TGenerator::SetViewRange(Float_t xmin, Float_t ymin, Float_t zmin, Float_t xmax, Float_t ymax, Float_t zmax)
 
  561    TView *view = gPad->GetView();
 
  563    view->SetRange(xmin,ymin,zmin,xmax,ymax,zmax);
 
  574 void TGenerator::ShowNeutrons(Bool_t show)
 
  576    fShowNeutrons = show;