00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 #include "TROOT.h"
00134 #include "TGenerator.h"
00135 #include "TDatabasePDG.h"
00136 #include "TParticlePDG.h"
00137 #include "TParticle.h"
00138 #include "TObjArray.h"
00139 #include "Hepevt.h"
00140 #include "TVirtualPad.h"
00141 #include "TView.h"
00142 #include "TText.h"
00143 #include "TPaveText.h"
00144 #include "TClonesArray.h"
00145 #include "Riostream.h"
00146
00147
00148 ClassImp(TGenerator)
00149
00150
00151 TGenerator::TGenerator(const char *name,const char *title): TNamed(name,title)
00152 {
00153
00154
00155
00156
00157 TDatabasePDG::Instance();
00158
00159
00160
00161 fPtCut = 0;
00162 fShowNeutrons = kTRUE;
00163 fParticles = new TObjArray(10000);
00164 }
00165
00166
00167 TGenerator::~TGenerator()
00168 {
00169
00170
00171
00172
00173 if (fParticles) {
00174 fParticles->Delete();
00175 delete fParticles;
00176 fParticles = 0;
00177 }
00178 }
00179
00180
00181 void TGenerator::GenerateEvent()
00182 {
00183
00184 }
00185
00186
00187 TObjArray* TGenerator::ImportParticles(Option_t *option)
00188 {
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 fParticles->Clear();
00200 Int_t numpart = HEPEVT.nhep;
00201 if (!strcmp(option,"") || !strcmp(option,"Final")) {
00202 for (Int_t i = 0; i<numpart; i++) {
00203 if (HEPEVT.isthep[i] == 1) {
00204
00205
00206
00207 TParticle *p = new TParticle(
00208 HEPEVT.idhep[i],
00209 HEPEVT.isthep[i],
00210 HEPEVT.jmohep[i][0]-1,
00211 HEPEVT.jmohep[i][1]-1,
00212 HEPEVT.jdahep[i][0]-1,
00213 HEPEVT.jdahep[i][1]-1,
00214 HEPEVT.phep[i][0],
00215 HEPEVT.phep[i][1],
00216 HEPEVT.phep[i][2],
00217 HEPEVT.phep[i][3],
00218 HEPEVT.vhep[i][0],
00219 HEPEVT.vhep[i][1],
00220 HEPEVT.vhep[i][2],
00221 HEPEVT.vhep[i][3]);
00222 fParticles->Add(p);
00223 }
00224 }
00225 } else if (!strcmp(option,"All")) {
00226 for (Int_t i = 0; i<numpart; i++) {
00227 TParticle *p = new TParticle(
00228 HEPEVT.idhep[i],
00229 HEPEVT.isthep[i],
00230 HEPEVT.jmohep[i][0]-1,
00231 HEPEVT.jmohep[i][1]-1,
00232 HEPEVT.jdahep[i][0]-1,
00233 HEPEVT.jdahep[i][1]-1,
00234 HEPEVT.phep[i][0],
00235 HEPEVT.phep[i][1],
00236 HEPEVT.phep[i][2],
00237 HEPEVT.phep[i][3],
00238 HEPEVT.vhep[i][0],
00239 HEPEVT.vhep[i][1],
00240 HEPEVT.vhep[i][2],
00241 HEPEVT.vhep[i][3]);
00242 fParticles->Add(p);
00243 }
00244 }
00245 return fParticles;
00246 }
00247
00248
00249 Int_t TGenerator::ImportParticles(TClonesArray *particles, Option_t *option)
00250 {
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 if (particles == 0) return 0;
00264 TClonesArray &clonesParticles = *particles;
00265 clonesParticles.Clear();
00266 Int_t numpart = HEPEVT.nhep;
00267 if (!strcmp(option,"") || !strcmp(option,"Final")) {
00268 for (Int_t i = 0; i<numpart; i++) {
00269 if (HEPEVT.isthep[i] == 1) {
00270
00271
00272
00273 new(clonesParticles[i]) TParticle(
00274 HEPEVT.idhep[i],
00275 HEPEVT.isthep[i],
00276 HEPEVT.jmohep[i][0]-1,
00277 HEPEVT.jmohep[i][1]-1,
00278 HEPEVT.jdahep[i][0]-1,
00279 HEPEVT.jdahep[i][1]-1,
00280 HEPEVT.phep[i][0],
00281 HEPEVT.phep[i][1],
00282 HEPEVT.phep[i][2],
00283 HEPEVT.phep[i][3],
00284 HEPEVT.vhep[i][0],
00285 HEPEVT.vhep[i][1],
00286 HEPEVT.vhep[i][2],
00287 HEPEVT.vhep[i][3]);
00288 }
00289 }
00290 } else if (!strcmp(option,"All")) {
00291 for (Int_t i = 0; i<numpart; i++) {
00292 new(clonesParticles[i]) TParticle(
00293 HEPEVT.idhep[i],
00294 HEPEVT.isthep[i],
00295 HEPEVT.jmohep[i][0]-1,
00296 HEPEVT.jmohep[i][1]-1,
00297 HEPEVT.jdahep[i][0]-1,
00298 HEPEVT.jdahep[i][1]-1,
00299 HEPEVT.phep[i][0],
00300 HEPEVT.phep[i][1],
00301 HEPEVT.phep[i][2],
00302 HEPEVT.phep[i][3],
00303 HEPEVT.vhep[i][0],
00304 HEPEVT.vhep[i][1],
00305 HEPEVT.vhep[i][2],
00306 HEPEVT.vhep[i][3]);
00307 }
00308 }
00309 return numpart;
00310 }
00311
00312
00313 void TGenerator::Browse(TBrowser *)
00314 {
00315
00316 Draw();
00317 gPad->Update();
00318 }
00319
00320
00321 Int_t TGenerator::DistancetoPrimitive(Int_t px, Int_t py)
00322 {
00323
00324
00325
00326
00327 const Int_t big = 9999;
00328 const Int_t inview = 0;
00329 Int_t dist = big;
00330 if (px > 50 && py > 50) dist = inview;
00331 return dist;
00332 }
00333
00334
00335 void TGenerator::Draw(Option_t *option)
00336 {
00337
00338
00339
00340
00341
00342 if (!gPad) {
00343 gROOT->MakeDefCanvas();
00344 gPad->GetVirtCanvas()->SetFillColor(13);
00345 }
00346
00347 static Float_t rbox = 1000;
00348 Float_t rmin[3],rmax[3];
00349 TView *view = gPad->GetView();
00350 if (!strstr(option,"same")) {
00351 if (view) { view->GetRange(rmin,rmax); rbox = rmax[2];}
00352 gPad->Clear();
00353 }
00354
00355 AppendPad(option);
00356
00357 view = gPad->GetView();
00358
00359 if (view) {
00360 view->GetRange(rmin,rmax);
00361 rbox = rmax[2];
00362 } else {
00363 view = TView::CreateView(1,0,0);
00364 view->SetRange(-rbox,-rbox,-rbox, rbox,rbox,rbox );
00365 }
00366 const Int_t kColorProton = 4;
00367 const Int_t kColorNeutron = 5;
00368 const Int_t kColorAntiProton= 3;
00369 const Int_t kColorPionPlus = 6;
00370 const Int_t kColorPionMinus = 2;
00371 const Int_t kColorKaons = 7;
00372 const Int_t kColorElectrons = 0;
00373 const Int_t kColorGamma = 18;
00374
00375 Int_t nProtons = 0;
00376 Int_t nNeutrons = 0;
00377 Int_t nAntiProtons= 0;
00378 Int_t nPionPlus = 0;
00379 Int_t nPionMinus = 0;
00380 Int_t nKaons = 0;
00381 Int_t nElectrons = 0;
00382 Int_t nGammas = 0;
00383
00384 Int_t ntracks = fParticles->GetEntriesFast();
00385 Int_t i,lwidth,color,lstyle;
00386 TParticlePDG *ap;
00387 TParticle *p;
00388 const char *name;
00389 Double_t etot,vx,vy,vz;
00390 Int_t ninvol = 0;
00391 for (i=0;i<ntracks;i++) {
00392 p = (TParticle*)fParticles->UncheckedAt(i);
00393 if(!p) continue;
00394 ap = (TParticlePDG*)p->GetPDG();
00395 vx = p->Vx();
00396 vy = p->Vy();
00397 vz = p->Vz();
00398 if (vx*vx+vy*vy+vz*vz > rbox*rbox) continue;
00399 Float_t pt = p->Pt();
00400 if (pt < fPtCut) continue;
00401 etot = p->Energy();
00402 if (etot > 0.1) lwidth = Int_t(6*TMath::Log10(etot));
00403 else lwidth = 1;
00404 if (lwidth < 1) lwidth = 1;
00405 lstyle = 1;
00406 color = 0;
00407 name = ap->GetName();
00408 if (!strcmp(name,"n")) { if (!fShowNeutrons) continue;
00409 color = kColorNeutron; nNeutrons++;}
00410 if (!strcmp(name,"p")) { color = kColorProton; nProtons++;}
00411 if (!strcmp(name,"p bar")) { color = kColorAntiProton; nAntiProtons++;}
00412 if (!strcmp(name,"pi+")) { color = kColorPionPlus; nPionPlus++;}
00413 if (!strcmp(name,"pi-")) { color = kColorPionMinus; nPionMinus++;}
00414 if (!strcmp(name,"e+")) { color = kColorElectrons; nElectrons++;}
00415 if (!strcmp(name,"e-")) { color = kColorElectrons; nElectrons++;}
00416 if (!strcmp(name,"gamma")) { color = kColorGamma; nGammas++; lstyle = 3; }
00417 if ( strstr(name,"K")) { color = kColorKaons; nKaons++;}
00418 p->SetLineColor(color);
00419 p->SetLineStyle(lstyle);
00420 p->SetLineWidth(lwidth);
00421 p->AppendPad();
00422 ninvol++;
00423 }
00424
00425
00426 TPaveText *pt = new TPaveText(-0.94,0.85,-0.25,0.98,"br");
00427 pt->AddText((char*)GetName());
00428 pt->AddText((char*)GetTitle());
00429 pt->SetFillColor(42);
00430 pt->Draw();
00431
00432
00433 Int_t tcolor = 5;
00434 if (gPad->GetFillColor() == 10) tcolor = 4;
00435 TText *text = new TText(-0.95,-0.47,"Particles");
00436 text->SetTextAlign(12);
00437 text->SetTextSize(0.025);
00438 text->SetTextColor(tcolor);
00439 text->Draw();
00440 text->SetTextColor(kColorGamma); text->DrawText(-0.95,-0.52,"(on screen)");
00441 text->SetTextColor(kColorGamma); text->DrawText(-0.95,-0.57,"Gamma");
00442 text->SetTextColor(kColorProton); text->DrawText(-0.95,-0.62,"Proton");
00443 text->SetTextColor(kColorNeutron); text->DrawText(-0.95,-0.67,"Neutron");
00444 text->SetTextColor(kColorAntiProton); text->DrawText(-0.95,-0.72,"AntiProton");
00445 text->SetTextColor(kColorPionPlus); text->DrawText(-0.95,-0.77,"Pion +");
00446 text->SetTextColor(kColorPionMinus); text->DrawText(-0.95,-0.82,"Pion -");
00447 text->SetTextColor(kColorKaons); text->DrawText(-0.95,-0.87,"Kaons");
00448 text->SetTextColor(kColorElectrons); text->DrawText(-0.95,-0.92,"Electrons,etc.");
00449
00450 text->SetTextColor(tcolor);
00451 text->SetTextAlign(32);
00452 char tcount[32];
00453 snprintf(tcount,12,"%d",ntracks); text->DrawText(-0.55,-0.47,tcount);
00454 snprintf(tcount,12,"%d",ninvol); text->DrawText(-0.55,-0.52,tcount);
00455 snprintf(tcount,12,"%d",nGammas); text->DrawText(-0.55,-0.57,tcount);
00456 snprintf(tcount,12,"%d",nProtons); text->DrawText(-0.55,-0.62,tcount);
00457 snprintf(tcount,12,"%d",nNeutrons); text->DrawText(-0.55,-0.67,tcount);
00458 snprintf(tcount,12,"%d",nAntiProtons); text->DrawText(-0.55,-0.72,tcount);
00459 snprintf(tcount,12,"%d",nPionPlus); text->DrawText(-0.55,-0.77,tcount);
00460 snprintf(tcount,12,"%d",nPionMinus); text->DrawText(-0.55,-0.82,tcount);
00461 snprintf(tcount,12,"%d",nKaons); text->DrawText(-0.55,-0.87,tcount);
00462 snprintf(tcount,12,"%d",nElectrons); text->DrawText(-0.55,-0.92,tcount);
00463
00464 snprintf(tcount,12,"Protons/Pions= %4f",Float_t(nProtons)/Float_t(nPionPlus+nPionMinus));
00465 text->SetTextAlign(12);
00466 text->DrawText(-0.45,-0.92,tcount);
00467 snprintf(tcount,12,"Kaons/Pions= %4f",Float_t(nKaons)/Float_t(nPionPlus+nPionMinus));
00468 text->DrawText(0.30,-0.92,tcount);
00469 }
00470
00471
00472
00473 void TGenerator::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00474 {
00475
00476
00477
00478 if (gPad->GetView()) {
00479 gPad->GetView()->ExecuteRotateView(event, px, py);
00480 return;
00481 }
00482 }
00483
00484
00485 Int_t TGenerator::GetNumberOfParticles() const
00486 {
00487
00488
00489 return fParticles->GetLast()+1;
00490 }
00491
00492
00493 TParticle *TGenerator::GetParticle(Int_t i) const
00494 {
00495
00496
00497
00498 if (!fParticles) return 0;
00499 Int_t n = fParticles->GetLast();
00500 if (i < 0 || i > n) return 0;
00501 return (TParticle*)fParticles->UncheckedAt(i);
00502 }
00503
00504
00505 void TGenerator::Paint(Option_t *)
00506 {
00507
00508
00509
00510
00511 }
00512
00513
00514 void TGenerator::SetPtCut(Float_t ptcut)
00515 {
00516
00517
00518
00519 fPtCut = ptcut;
00520 Draw();
00521 gPad->Update();
00522 }
00523
00524
00525 void TGenerator::SetViewRadius(Float_t rbox)
00526 {
00527
00528
00529
00530 SetViewRange(-rbox,-rbox,-rbox,rbox,rbox,rbox);
00531 }
00532
00533
00534 void TGenerator::SetViewRange(Float_t xmin, Float_t ymin, Float_t zmin, Float_t xmax, Float_t ymax, Float_t zmax)
00535 {
00536
00537
00538
00539 TView *view = gPad->GetView();
00540 if (!view) return;
00541 view->SetRange(xmin,ymin,zmin,xmax,ymax,zmax);
00542
00543 Draw();
00544 gPad->Update();
00545 }
00546
00547
00548 void TGenerator::ShowNeutrons(Bool_t show)
00549 {
00550
00551
00552
00553 fShowNeutrons = show;
00554 Draw();
00555 gPad->Update();
00556 }