Changeset 1374 for trunk/WuerzburgSoft
- Timestamp:
- 06/21/02 08:28:43 (22 years ago)
- Location:
- trunk/WuerzburgSoft/Thomas/mphys
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WuerzburgSoft/Thomas/mphys/Changelog
r1373 r1374 1 1 -*-*- END -*-*- 2 2002/06/20: Thomas Bretz 3 4 * analp.C: 5 - clean up the code 6 - added the point-spread histograms from different directions 7 8 * mphys.C: 9 - removed the angular histograms 10 - added the plot spectral index 11 - added the timer to get a usable ubdated window 12 13 14 2 15 2002/06/20: Thomas Bretz 3 16 -
trunk/WuerzburgSoft/Thomas/mphys/analp.C
r1370 r1374 2 2 3 3 #include <float.h> 4 4 5 Double_t GetMin(TH1 *h) 5 6 { … … 13 14 } 14 15 15 void GetRange(TChain *chain, const char *name, Double_t &min, Double_t &max)16 void GetRange(TChain *chain, const char *name, Int_t &nbins, Double_t &min, Double_t &max, Double_t conv=1) 16 17 { 17 18 TString str("MPhoton.MParticle."); … … 32 33 if (!leaf) 33 34 return 0; 35 34 36 Double_t val = leaf->GetValue(); 35 37 … … 42 44 max = val; 43 45 } 46 47 min *= conv; 48 max *= conv; 49 50 chain.GetPlayer(); 51 TTreePlayer &play = *chain.GetPlayer(); 52 53 Int_t n; 54 play.FindGoodLimits(nbins, n, min, max, kFALSE); 55 nbins = n; 44 56 } 45 57 … … 47 59 { 48 60 TChain chain("Photons"); 49 // chain.Add("cascade_100kpc_a_1e6.root");50 // chain.Add("cascade_100kpc_b_1e6.root"); 51 // chain.Add("cascade_500kpc_0*.root");52 chain.Add("cascade_500kpc_21d_0*.root");53 // chain.Add("cascade_100kpc_0*.root"); 54 // chain.Add("cascade_100kpc_14*.root");55 // chain.Add("cascade_100kpc_0*.root");56 // chain.Add("cascade_500kpc_21d_*.root"); 57 // chain.Add("cascade_100kpc_4*.root");58 // chain.Add("cascade_500kpc_21d_B1e-18_*.root"); 59 61 chain.Add("cascade_500kpc_*.root"); 62 63 MBinning binsx; 64 binsx.SetEdgesLog(21, 1e4, 1e11); 65 66 Double_t alpha = -1.8; 67 Double_t plot = 1.8; 68 69 Int_t nbins = 20; 70 71 // ------------------------------ 60 72 61 73 Int_t n = chain.GetEntries(); 62 74 63 cout << "Found " << n << " entries." << endl;75 cout << endl << "Found " << n << " entries." << endl; 64 76 65 77 if (n==0) 66 78 return; 67 68 MBinning binsx;69 binsx.SetEdgesLog(21, 1e4, 1e11);70 79 71 80 MBinning binspolx; … … 74 83 binspolx.SetEdges(16, -180, 180); 75 84 76 const Double_t ls = 299792458; // [m/s] 77 const Double_t ly = 3600.*24.*365.*ls; // [m/ly] 78 const Double_t pc = 1./3.258; // [pc/ly] 79 80 Double_t max; 81 Double_t min; 82 Int_t nbins=20; 83 84 TTreePlayer &play = *chain.GetPlayer(); 85 86 GetRange(&chain, "fTheta", min, max); 87 Double_t conv = kRad2Deg*60; 88 min *= conv; 89 max *= conv; 90 cout << "fTheta: " << min << " < " << max << " [']" << endl; 91 play.FindGoodLimits(10, nbins, min, max, kFALSE); 92 cout << " " << nbins << ": " << min << " < " << max << endl; 85 Double_t min, max; 86 GetRange(&chain, "fTheta", nbins, min, max, kRad2Deg*60); 93 87 binspola.SetEdges(nbins, min, max); 94 95 GetRange(&chain, "fR", min, max); 96 max/=4; 97 cout << "fR: " << min << " < " << max << " [kpc]" << endl; 98 play.FindGoodLimits(10, nbins, min, max, kFALSE); 99 cout << " " << nbins << ": " << min << " < " << max << endl; 88 cout << "fTheta, " << nbins << ": " << min << " ... " << max << " [']" << endl; 89 90 GetRange(&chain, "fR", nbins, min, max); 100 91 binspolr.SetEdges(nbins, min, max); 92 cout << "fR, " << nbins << ": " << min << " ... " << max << " [kpc]" << endl; 101 93 102 94 TH1D h; 103 h.SetName("Photons");95 TH1D prim; 104 96 MH::SetBinning(&h, &binsx); 105 106 TH1D prim;107 97 MH::SetBinning(&prim, &binsx); 108 98 … … 115 105 chain.SetBranchAddress("MPhoton.", &p); 116 106 117 Double_t weight = 0; 118 Double_t alpha = -2; 119 Double_t plot = 2; 120 Double_t E; 107 chain.GetEntry(0); 108 if (!p->IsPrimary()) 109 return; 110 111 Double_t z = p->GetZ(); 112 Double_t R = MParticle::RofZ(&z); 113 114 cout << "Z = " << z << endl; 115 cout << "R = " << R << "kpc" << endl; 116 117 Double_t weight = 0; 118 121 119 for (int i=0; i<n; i++) 122 120 { … … 125 123 Double_t Ep = p->GetEnergy(); 126 124 127 if (i==0)128 weight = pow(Ep, alpha);129 130 125 if (p->IsPrimary()) 131 126 { 132 127 weight = pow(Ep, alpha); 133 prim.Fill(Ep, pow(Ep,plot) * weight); 134 E = Ep; 128 prim.Fill(Ep, pow(Ep, plot+alpha)); 135 129 continue; 136 130 } 137 131 138 //if (Ep==E)139 // continue;140 141 132 h.Fill(Ep, pow(Ep,plot) * weight); 142 Double_t v = p->GetPhi()*kRad2Deg; 143 r.Fill(fmod(v+180, 360)-180, p->GetR(), weight); 144 v = p->GetPsi()*kRad2Deg; 145 a.Fill(fmod(v+180, 360)-180, p->GetTheta()*kRad2Deg*60, weight); 133 134 Double_t phi = fmod(p->GetPhi()*kRad2Deg+180, 360)-180; 135 Double_t psi = fmod(p->GetPsi()*kRad2Deg+180, 360)-180; 136 137 r.Fill(phi, p->GetR(), weight); 138 a.Fill(psi, p->GetTheta()*kRad2Deg*60, weight); 146 139 } 147 140 … … 163 156 c->Divide(2,2); 164 157 158 gStyle->SetPalette(1, 0); 159 165 160 c->cd(1); 166 gPad->SetLogy();167 gPad->SetLogz();168 gPad->SetTheta(70);169 gPad->SetPhi(90);170 h.SetTitle(Form(" E^{%.1f} Spectra ", alpha));171 h.SetXTitle("E\\gamma [GeV]");172 h.SetYTitle(Form("E^{%.1f} * Counts", plot));173 161 r.SetTitle(" Distance from Observer "); 174 162 r.GetXaxis()->SetLabelOffset(-0.015); … … 177 165 r.SetXTitle("\\Phi [\\circ]"); 178 166 r.SetYTitle("R [kpc]"); 179 r.DrawCopy("surf1pol"); 167 TPad &pad = *gPad; 168 pad.Divide(2,2); 169 pad.cd(1); 170 gPad->SetLogy(); 171 gPad->SetLogz(); 172 gPad->SetTheta(0); 173 gPad->SetPhi(90); 174 g = r.DrawCopy("surf1pol"); 175 pad.cd(2); 176 gPad->SetLogy(); 177 gPad->SetLogz(); 178 gPad->SetTheta(70); 179 gPad->SetPhi(90); 180 g->Draw("surf1pol"); 181 pad.cd(3); 182 gPad->SetLogy(); 183 gPad->SetLogz(); 184 gPad->SetTheta(90); 185 gPad->SetPhi(90); 186 g->Draw("surf1pol"); 187 pad.cd(4); 188 gPad->SetLogy(); 189 gPad->SetLogz(); 190 gPad->SetTheta(20); 191 gPad->SetPhi(90); 192 g->Draw("surf1pol"); 180 193 181 194 c->cd(2); 182 gPad->SetLogy();183 gPad->SetLogz();184 gPad->SetTheta(70);185 gPad->SetPhi(90);186 195 a.SetTitle(" Hit Angle for Observer "); 187 196 a.GetXaxis()->SetLabelOffset(-0.015); … … 190 199 a.SetXTitle("\\Psi [\\circ]"); 191 200 a.SetYTitle("\\Theta [']"); 192 a.DrawCopy("surf1pol"); 201 TPad &pad = *gPad; 202 pad.Divide(2,2); 203 pad.cd(1); 204 gPad->SetLogy(); 205 gPad->SetLogz(); 206 gPad->SetTheta(0); 207 gPad->SetPhi(90); 208 g = a.DrawCopy("surf1pol"); 209 pad.cd(2); 210 gPad->SetLogy(); 211 gPad->SetLogz(); 212 gPad->SetTheta(70); 213 gPad->SetPhi(90); 214 g->Draw("surf1pol"); 215 pad.cd(3); 216 gPad->SetLogy(); 217 gPad->SetLogz(); 218 gPad->SetTheta(90); 219 gPad->SetPhi(90); 220 g->Draw("surf1pol"); 221 pad.cd(4); 222 gPad->SetLogy(); 223 gPad->SetLogz(); 224 gPad->SetTheta(20); 225 gPad->SetPhi(90); 226 g->Draw("surf1pol"); 193 227 194 228 c->cd(3); … … 227 261 gPad->SetLogx(); 228 262 gPad->SetLogy(); 229 prim.SetFillStyle(0);230 263 h.SetFillStyle(0); 264 h.SetName("Photons"); 265 h.SetTitle(Form(" E^{%.1f} Spectra ", alpha)); 266 h.SetXTitle("E\\gamma [GeV]"); 267 h.SetYTitle(Form("E^{%.1f} * Counts", plot)); 231 268 h.GetXaxis()->SetLabelOffset(-0.015); 232 269 h.GetXaxis()->SetTitleOffset(1.1); 233 // h.GetXaxis()->SetRangeUser(1e4, 1e9); 270 h.SetMarkerStyle(kMultiply); 271 prim.SetFillStyle(0); 234 272 prim.SetMarkerStyle(kPlus); 235 h.SetMarkerStyle(kMultiply);236 273 prim.SetMarkerColor(kRed); 237 274 prim.SetLineColor(kRed); 238 239 h.DrawCopy("P"); 240 prim.DrawCopy("Psame"); 241 prim.DrawCopy("Csame"); 242 h.DrawCopy("Csame"); 275 TH1 &g1=*h.DrawCopy("P"); 276 TH1 &g2=*prim.DrawCopy("Psame"); 277 g2.Draw("Csame"); 278 g1.Draw("Csame"); 243 279 244 280 c->cd(2); -
trunk/WuerzburgSoft/Thomas/mphys/phys.C
r1373 r1374 10 10 #include <TFile.h> 11 11 #include <TTree.h> 12 #include <TTimer.h> 13 #include <TStyle.h> 12 14 #include <TBranch.h> 13 #include <TStyle.h>14 15 #include <TRandom.h> 15 16 #include <TCanvas.h> … … 121 122 Double_t startz = MParticle::ZofR(&R); 122 123 123 const char *filename = " data/cascade_delme.root";124 const char *filename = "cascade_delme.root"; 124 125 125 126 const Double_t B = 0; … … 128 129 cout << "Z = " << startz << endl; 129 130 130 static TRandom rand(0);131 131 MPairProduction pair; 132 132 133 Double_t runtime = 60; // [s]133 Double_t runtime = 5*60; // [s] 134 134 135 135 Double_t lo = 1e4; 136 136 Double_t hi = 1e11; 137 137 Double_t alpha = -2; 138 Double_t plot = 2; 138 139 139 140 Int_t nbins = 21; //4*log10(hi/lo); … … 142 143 TH1D histsrc; 143 144 144 hist.SetMinimum( lo*lo * pow(lo,alpha)/10);145 histsrc.SetMinimum( lo*lo * pow(lo,alpha)/10);145 hist.SetMinimum(pow(lo, plot+alpha)/10); 146 histsrc.SetMinimum(pow(lo, plot+alpha)/10); 146 147 147 148 TList listg; … … 152 153 153 154 gStyle->SetOptStat(10); 154 155 TH2D position;156 TH2D angle;157 TH1D histpos;158 TH1D hista;159 160 MBinning binspolx;161 MBinning binspoly1;162 MBinning binspoly2;163 binspolx.SetEdges(16, -180, 180);164 binspoly1.SetEdges(20, 0, 5e-6);165 binspoly2.SetEdges(20, 0, 1e-5);166 MH::SetBinning(&angle, &binspolx, &binspoly1);167 MH::SetBinning(&position, &binspolx, &binspoly2);168 MH::SetBinning(&hista, &binspoly1);169 MH::SetBinning(&histpos, &binspoly2);170 171 hista.SetTitle("Particle Angle");172 angle.SetTitle("Particle Angle");173 histpos.SetTitle("Particle Position");174 position.SetTitle("Particle Position");175 155 176 156 // … … 190 170 MH::SetBinning(&histsrc, &bins); 191 171 192 MH::MakeDefCanvas();172 TCanvas *c=MH::MakeDefCanvas(); 193 173 194 174 gPad->SetGrid(); … … 196 176 gPad->SetLogy(); 197 177 198 hist src.SetName("Spectrum");199 hist src.SetXTitle("E [GeV]");200 hist src.SetYTitle("E^{2}\\dotCounts");201 hist src.GetXaxis()->SetLabelOffset(-0.015);202 hist src.GetXaxis()->SetTitleOffset(1.1);203 204 hist src.Draw("P");205 hist .Draw("Psame");206 histsrc.Draw(" Csame");207 hist.Draw(" Csame");178 hist.SetName("Spectrum"); 179 hist.SetXTitle("E [GeV]"); 180 hist.SetYTitle(Form("E^{%.1f} Counts", plot)); 181 hist.GetXaxis()->SetLabelOffset(-0.015); 182 hist.GetXaxis()->SetTitleOffset(1.1); 183 184 hist.Draw("P"); 185 histsrc.Draw("Psame"); 186 histsrc.Draw("same"); 187 hist.Draw("same"); 208 188 209 189 // ------------------------------ 210 190 211 MPhoton *p4file = NULL; 212 MElectron *e4file = NULL; 213 191 void *ptr = NULL; 214 192 TFile file(filename, "RECREATE", "Intergalactic cascade", 9); 215 TTree *T1 = new TTree("Photons","Photons from Cascade");216 TTree *T2 = new TTree("Electrons","Electrons in the Cascade");217 TBranch *B1 = T1->Branch("MPhoton.", "MPhoton", &p 4file, 32000);218 TBranch *B2 = T2->Branch("MElectron.", "MElectron", & e4file, 32000);193 TTree *T1 = new TTree ("Photons", "Photons from Cascade"); 194 TTree *T2 = new TTree ("Electrons", "Electrons in the Cascade"); 195 TBranch *B1 = T1->Branch("MPhoton.", "MPhoton", &ptr); 196 TBranch *B2 = T2->Branch("MElectron.", "MElectron", &ptr); 219 197 220 198 // ------------------------------ 199 200 TTimer timer("gSystem->ProcessEvents();", 250, kFALSE); 201 timer.TurnOn(); 221 202 222 203 TStopwatch clock; 223 204 clock.Start(); 224 225 Int_t timer = 0;226 205 227 206 Int_t n=0; … … 234 213 Double_t E = GetEnergy(nbins, lo, hi); 235 214 Double_t weight = pow(E, alpha); 236 histsrc.Fill(E, E*E* weight);215 histsrc.Fill(E, pow(E, plot) * weight); 237 216 238 217 MPhoton *gamma=new MPhoton(E, startz); … … 248 227 Double_t Esum=0; 249 228 Double_t Emis=0; 250 251 229 while (1) 252 230 { … … 265 243 cout << "!" << flush; 266 244 267 hist.Fill(Eg, Eg*Eg*weight); 268 position.Fill(p->GetPhi()*kRad2Deg, p->GetR(), weight); 269 angle.Fill(p->GetPsi()*kRad2Deg, p->GetTheta()*kRad2Deg, weight); 270 histpos.Fill(p->GetR(), weight); 271 hista.Fill(p->GetTheta()*kRad2Deg, weight); 245 hist.Fill(Eg, pow(Eg, plot)*weight); 272 246 273 247 p->SetIsPrimary(kFALSE); … … 286 260 phot.SetParameter(0, Eg); 287 261 phot.SetParameter(1, p->GetZ()); 288 /* 289 if (phot.Integral(-log10(Eg)-8, -10.5, (Double_t*)NULL, 1e-2)==0) 290 { 291 cout << "z" << flush; 292 continue; 293 } 294 */ 262 295 263 Double_t Ep = pow(10, phot.GetRandom()); 296 264 if (Ep==pow(10,0)) … … 327 295 while ((e=(MElectron*)Next())) 328 296 { 329 e->SetIsPrimary( );297 e->SetIsPrimary(kTRUE); 330 298 T2->Fill(); 331 299 e->SetIsPrimary(kFALSE); … … 340 308 { 341 309 cout << "!" << flush; 342 Esum += e->GetEnergy();343 Emis += e->GetEnergy();344 310 break; 345 311 } 346 312 347 313 // WRONG! 348 Double_t theta = 0; //rand.Uniform(TMath::Pi()/2)+TMath::Pi()*3/4; 349 MPhoton *p = e->DoInvCompton(theta); 314 MPhoton *p = e->DoInvCompton(0); 350 315 351 316 T2->Fill(); … … 371 336 { 372 337 cout << "T" << flush; 373 Esum += e->GetEnergy();374 Emis += e->GetEnergy();375 338 break; 376 339 } … … 379 342 { 380 343 cout << "E" << flush; 381 Esum += e->GetEnergy();382 Emis += e->GetEnergy();383 344 break; 384 345 } 385 346 } 347 Esum += e->GetEnergy(); 348 Emis += e->GetEnergy(); 386 349 } 387 350 liste.Delete(); … … 389 352 cout << " ----> " << Form("%3.1f %3.1e / %3.1f %3.1e", Emis/E, Emis, Esum/E, Esum) << endl; 390 353 391 Int_t now = (int)(TStopwatch::GetRealTime()- starttime)/5; 392 if (now!=timer || n<10) 393 { 394 histsrc.SetTitle(Form("E^%.1f, z=%f, T=%d'%d\", N=%d", alpha, startz, 395 (int)runtime/60, (int)runtime%60, hist.GetEntries())); 396 gPad->Modified(); 397 gPad->Update(); 398 timer = now; 399 } 354 hist.SetTitle(Form("E^{%.1f} z=%f T=%d'%d\" N=%d", alpha, startz, 355 (int)runtime/60, (int)runtime%60, n)); 356 357 timer.Stop(); 358 c->Update(); 359 timer.Start(250); 400 360 401 361 } … … 405 365 clock.Print(); 406 366 367 timer.Stop(); 368 407 369 file.Write(); 408 370 … … 414 376 gPad->Clear(); 415 377 416 hist.SetTitle(Form("E^%.1f, z=%f, T=%d'%d\", N=%d", alpha, startz, (int)runtime/60, (int)runtime%60, n)); 417 gPad->Modified(); 418 gPad->Update(); 419 420 hist.DrawCopy("P"); 421 histsrc.DrawCopy("Psame"); 422 hist.DrawCopy("Csame"); 423 histsrc.DrawCopy("Csame"); 424 425 gPad->SetGrid(); 426 gPad->SetLogx(); 427 gPad->SetLogy(); 428 429 MH::MakeDefCanvas(); 430 position.SetXTitle("Pos: \\Phi [\\circ]"); 431 position.SetYTitle("Pos: R [kpc]"); 432 position.DrawCopy("surf1pol"); 433 //gPad->SetLogy(); 434 435 MH::MakeDefCanvas(); 436 angle.SetXTitle("Angle: \\Psi [\\circ]"); 437 angle.SetYTitle("Angle: \\Theta [\\circ]"); 438 angle.DrawCopy("surf1pol"); 439 //gPad->SetLogy(); 440 441 MH::MakeDefCanvas(); 442 histpos.SetXTitle("R [kpc]"); 443 histpos.SetYTitle("Counts"); 444 histpos.DrawCopy(); 445 gPad->SetLogx(); 446 447 MH::MakeDefCanvas(); 448 hista.SetXTitle("\\Theta [\\circ]"); 449 hista.SetYTitle("Counts"); 450 hista.DrawCopy(); 451 gPad->SetLogx(); 378 hist.SetTitle(Form("E^{%.1f} z=%f T=%d'%d\" N=%d", alpha, startz, (int)runtime/60, (int)runtime%60, n)); 379 380 TH1 &h1 = *hist.DrawCopy("P"); 381 TH1 &h2 = *histsrc.DrawCopy("Psame"); 382 h2.Draw("Csame"); 383 h1.Draw("Csame"); 452 384 } 453 385
Note:
See TracChangeset
for help on using the changeset viewer.