TH1D* hedep; TH1D* htedep; TH2D* hposedepFWD; TH2D* hposedepBWD; TH1D* hHits1; TH3D* hposfwd; TH3D* hposbwd; TH1D* hspec; float edep; TH2D* hvertpos1; TH2D* hvertpos2; TH1D* hpdgstr; TH1D* hpdgmc; void analyze_Begin(TTree*) { // Initialize histograms hedep=new TH1D("evt shw energy","summed shower.ph.gev per event",100,0,0); htedep=new TH1D("htedep","energy per crystal [GeV];cellID;Edep[GeV]",8,0.5,8.5); hposedepFWD = new TH2D("hposedepFWD", "Positions of energy deposition in FWD; x[cm]; y[cm]", 100, 0, 0, 100, 0, 0); hposedepBWD = new TH2D("hposedepBWD", "Positions of energy deposition in BWD; x[cm]; y[cm]", 100, 0, 0, 100, 0, 0); hHits1 = new TH1D("hhits1", "Number of hits per crystal per ms", 8, 0.5, 8.5); hHits1->GetXaxis()->SetTitle("CellID"); hHits1->GetYaxis()->SetTitle("# of hits"); hposfwd = new TH3D("posfwd", "Edep per crystal per ms; x[cm];y[cm];z[cm]", 100, 0, 0, 100, 0, 0, 100, 0, 0); hposbwd = new TH3D("posbwd", "Edep per crystal per ms; x[cm];y[cm];z[cm]", 100, 0, 0, 100, 0, 0, 100, 0, 0); hspec = new TH1D("spectrum", "Spectrum of hits - total Edep per hit;totEdep[GeV];#ofHits", 100, 0, 0); hvertpos1 = new TH2D("vertexPosition1", "Position of the beam hits; z[cm]; y[cm]", 100, 0, 0, 100, 0, 0); hvertpos2 = new TH2D("vertexPosition2", "Position of the beam hits; z[cm]; y[cm]", 100, 0, 0, 100, 0, 0); hpdgstr = new TH1D("pdgstr", "Particle type;pdgCode;#ofParticles", 3000, 0, 3000); hpdgmc = new TH1D("pdgmc", "Particle type generated;pdgCode;#ofParticles", 3000, 0, 0); } double analyze() { for(int j =0; j < MCParticles.GetEntries(); j++){ hpdgmc->Fill(MCParticles.m_pdg[j]); //cout << MCParticles.m_pdg[j] << endl; } edep = 0; if (StrSimHits.m_Edep[0] != 0){ hvertpos1->Fill(MCParticles.m_productionVertex_z[0], MCParticles.m_productionVertex_y[0]); } for (int i=0; i < StrSimHits.GetEntries(); i++) { edep = edep + StrSimHits.m_Edep[i]; hedep->Fill(StrSimHits.m_Edep[i]); hpdgstr->Fill(StrSimHits.m_Pdg[i]); if (StrSimHits.m_Position[i]->Z() >=0){ hposfwd->Fill(StrSimHits.m_Position[i]->X(), StrSimHits.m_Position[i]->Y(), StrSimHits.m_Position[i]->Z(), StrSimHits.m_Edep[i]); hposedepFWD -> Fill(StrSimHits.m_Position[i]->X(), StrSimHits.m_Position[i]->Y(), StrSimHits.m_Edep[i]); if (StrSimHits.m_Position[i]->X() > 20 && StrSimHits.m_Position[i]->Y()< 10){ htedep->Fill(0.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(0.5, 1); } if (StrSimHits.m_Position[i]->Y() > 20 && StrSimHits.m_Position[i]->X() < 10){ htedep->Fill(1.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(1.5, 1); } if (StrSimHits.m_Position[i]->X () < -20 && StrSimHits.m_Position[i]->Y()< 10) { htedep->Fill(2.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(2.5, 1); } if (StrSimHits.m_Position[i]->Y() < -20 && StrSimHits.m_Position[i]->X() < 10) { htedep->Fill(3.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(3.5, 1); } } if (StrSimHits.m_Position[i]->Z() < 0) { hposedepBWD -> Fill(StrSimHits.m_Position[i]->X(), StrSimHits.m_Position[i]->Y(), StrSimHits.m_Edep[i]); hposbwd->Fill(StrSimHits.m_Position[i]->X(), StrSimHits.m_Position[i]->Y(), StrSimHits.m_Position[i]->Z(), StrSimHits.m_Edep[i]); if (StrSimHits.m_Position[i]->X() > 20){ htedep->Fill(4.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(4.5, 1); } if (StrSimHits.m_Position[i]->Y() > 20){ htedep->Fill(5.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(5.5, 1); } if (StrSimHits.m_Position[i]->X() < -20) { htedep->Fill(6.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(6.5, 1); } if (StrSimHits.m_Position[i]->Y() < -20) { htedep->Fill(7.5, StrSimHits.m_Edep[i]); if (i == 0) hHits1->Fill(7.5, 1); } } } if (edep != 0) hspec->Fill(edep); return 0; } void analyze_Terminate() { //new TCanvas("c1","event energy canvas",200,10,700,780); //gROOT->LoadMacro("Belle2Style.C"); //SetBelle2Style(); std::string line; std::ifstream infile("types.txt"); if(infile.is_open()){ while (getline(infile, line)){ TFile* out = new TFile(Form("hist/result_%s.root",line.c_str()), "RECREATE"); out -> Delete("edepPerCrystal;*"); htedep -> Write("edepPerCrystal"); out -> Delete("bwdEdep;*"); out -> Delete("fwdEdep;*"); out -> Delete("hits;*"); out -> Delete("bwd3d;*"); out -> Delete("fwd3d;*"); out ->Delete("spec;*"); out -> Delete("vertPos;*"); out -> Delete("pdgstr;*"); out->Delete("pdgmc;*"); hvertpos1->Write("vertPos"); hspec ->Write("spec"); hposedepBWD ->Write("bwdEdep"); hposedepFWD -> Write("fwdEdep"); hposfwd -> Write("fwd3d"); hposbwd -> Write("bwd3d"); hHits1->Write("hits"); hpdgstr->Write("pdgstr"); hpdgmc->Write("pdgmc"); out -> Close(); } infile.close(); } }