Geant4 Cross Reference |
>> 1 { 1 struct SpeciesInfoAOS 2 struct SpeciesInfoAOS 2 { 3 { 3 SpeciesInfoAOS() << 4 SpeciesInfoAOS() 4 { << 5 { 5 fNEvent = 0; << 6 fNEvent = 0; 6 fNumber = 0; << 7 fNumber = 0; 7 fG = 0.; << 8 fG = 0.; 8 fG2 = 0.; << 9 fG2 = 0.; 9 } << 10 } 10 << 11 11 SpeciesInfoAOS(const SpeciesInfoAOS& right) << 12 SpeciesInfoAOS(const SpeciesInfoAOS& right) // Species A(B); 12 { << 13 { 13 fNEvent = right.fNEvent; << 14 fNEvent = right.fNEvent; 14 fNumber = right.fNumber; << 15 fNumber = right.fNumber; 15 fG = right.fG; << 16 fG = right.fG; 16 fG2 = right.fG2; << 17 fG2 = right.fG2; 17 fName = right.fName; << 18 fName = right.fName; 18 } << 19 } 19 << 20 20 SpeciesInfoAOS& operator=(const SpeciesInfo << 21 SpeciesInfoAOS& operator=(const SpeciesInfoAOS& right) // A = B 21 { << 22 { 22 if(&right == this) return *this; << 23 if(&right == this) return *this; 23 fNEvent = right.fNEvent; << 24 fNEvent = right.fNEvent; 24 fNumber = right.fNumber; << 25 fNumber = right.fNumber; 25 fG = right.fG; << 26 fG = right.fG; 26 fG2 = right.fG2; << 27 fG2 = right.fG2; 27 fName = right.fName; << 28 fName = right.fName; 28 return *this; << 29 return *this; 29 } << 30 } 30 << 31 31 Int_t fNEvent; << 32 Int_t fNEvent; 32 Int_t fNumber; << 33 Int_t fNumber; 33 Double_t fG; << 34 Double_t fG; 34 Double_t fG2; << 35 Double_t fG2; 35 string fName; << 36 string fName; 36 }; 37 }; 37 38 38 //-------------------------------------------- 39 //------------------------------------------------------------------------ 39 40 40 struct SpeciesInfoSOA 41 struct SpeciesInfoSOA 41 { 42 { 42 SpeciesInfoSOA() << 43 SpeciesInfoSOA() 43 { << 44 { 44 fRelatErr = 0; << 45 fRelatErr = 0; 45 } << 46 } 46 << 47 47 SpeciesInfoSOA(const SpeciesInfoSOA& right) << 48 SpeciesInfoSOA(const SpeciesInfoSOA& right) : 48 fG(right.fG), << 49 fG(right.fG), 49 fGerr(right.fGerr), << 50 fGerr(right.fGerr), 50 fTime(right.fTime), << 51 fTime(right.fTime), 51 fRelatErr(right.fRelatErr), << 52 fRelatErr(right.fRelatErr), 52 fName(right.fName) << 53 fName(right.fName) 53 {} << 54 {} 54 << 55 55 SpeciesInfoSOA& operator=(const SpeciesInfo << 56 SpeciesInfoSOA& operator=(const SpeciesInfoSOA& right) 56 { << 57 { 57 if(this == &right) return *this; << 58 if(this == &right) return *this; 58 fG = right.fG; << 59 fG = right.fG; 59 fGerr = right.fGerr; << 60 fGerr = right.fGerr; 60 fTime = right.fTime; << 61 fTime = right.fTime; 61 fRelatErr = right.fRelatErr; << 62 fRelatErr = right.fRelatErr; 62 fName = right.fName; << 63 fName = right.fName; 63 return *this; << 64 return *this; 64 } << 65 } 65 << 66 66 std::vector<Double_t> fG; << 67 std::vector<Double_t> fG; 67 std::vector<Double_t> fGerr; << 68 std::vector<Double_t> fGerr; 68 std::vector<Double_t> fTime; << 69 std::vector<Double_t> fTime; 69 Double_t fRelatErr; << 70 Double_t fRelatErr; 70 Double_t fMin, fMax; << 71 Double_t fMin, fMax; 71 string fName; << 72 string fName; 72 }; 73 }; 73 74 >> 75 void Save(); 74 const char* filetypes[] = { 76 const char* filetypes[] = { 75 "PostScript", "*.ps", << 77 "PostScript", "*.ps", 76 "Encapsulated PostScript", "*.eps", << 78 "Encapsulated PostScript", "*.eps", 77 "PDF files", "*.pdf", << 79 "PDF files", "*.pdf", 78 "Gif files", "*.gif", << 80 "Gif files", "*.gif", 79 "PNG files", "*.png", << 81 "PNG files", "*.png", 80 "All files", "*", << 82 "All files", "*", 81 0, 0 << 83 0, 0 82 }; 84 }; 83 85 84 TGTab *gTab = nullptr; << 86 gROOT->Reset(); >> 87 >> 88 gROOT->SetStyle("Plain"); >> 89 gStyle->SetPalette(1); >> 90 gStyle->SetCanvasBorderMode(0); >> 91 gStyle->SetFrameBorderMode(0); >> 92 gStyle->SetPadTickX(1); >> 93 gStyle->SetPadTickY(1); >> 94 >> 95 TGMainFrame *main = new TGMainFrame(gClient->GetRoot(), 200, 200); >> 96 TGTab *fTab = new TGTab(main, 200, 200); >> 97 >> 98 Double_t timeA, sumG, sumG2; >> 99 Int_t speciesID, number, nEvent; >> 100 char speciesName[500]; >> 101 >> 102 TFile* file = new TFile; >> 103 file = TFile::Open("scorer.root"); >> 104 TTree* tree = (TTree*)file->Get("species"); >> 105 tree->SetBranchAddress("speciesID", &speciesID); >> 106 tree->SetBranchAddress("number", &number); >> 107 tree->SetBranchAddress("nEvent", &nEvent); >> 108 tree->SetBranchAddress("speciesName", &speciesName); >> 109 tree->SetBranchAddress("time", &timeA); >> 110 tree->SetBranchAddress("sumG", &sumG); >> 111 tree->SetBranchAddress("sumG2", &sumG2); 85 112 86 void Save() << 113 Long64_t nentries = tree->GetEntries(); >> 114 >> 115 if(nentries == 0) 87 { 116 { 88 TGFileInfo fi; << 117 cout << "No entries found in the tree species contained in the file " 89 fi.fFileTypes = filetypes; << 118 << file->GetPath() << endl; >> 119 exit(1); >> 120 } 90 121 91 new TGFileDialog(gClient->GetRoot(),gClient << 122 std::map<int, std::map<double, SpeciesInfoAOS>> speciesTimeInfo; 92 gROOT->GetListOfCanvases()->At(gTab->GetCur << 123 >> 124 for (Int_t j=0; j < nentries; j++) >> 125 { >> 126 tree->GetEntry(j); >> 127 SpeciesInfoAOS& infoAOS = speciesTimeInfo[speciesID][timeA]; >> 128 infoAOS.fNumber += number; >> 129 infoAOS.fG += sumG; >> 130 infoAOS.fG2 += sumG2; >> 131 infoAOS.fNEvent += nEvent; >> 132 infoAOS.fName = speciesName; 93 } 133 } 94 134 >> 135 std::map<Int_t, SpeciesInfoSOA> speciesInfo; >> 136 >> 137 auto it_SOA = speciesTimeInfo.begin(); >> 138 auto end_SOA = speciesTimeInfo.end(); >> 139 95 140 96 void plotG() << 141 for(; it_SOA!=end_SOA;++it_SOA) 97 { 142 { 98 gROOT->SetStyle("Plain"); << 143 const Int_t _speciesID = it_SOA->first; 99 gStyle->SetPalette(1); << 144 SpeciesInfoSOA& info = speciesInfo[_speciesID]; 100 gStyle->SetCanvasBorderMode(0); << 145 101 gStyle->SetFrameBorderMode(0); << 146 auto it2 = it_SOA->second.begin(); 102 gStyle->SetPadTickX(1); << 147 auto end2 = it_SOA->second.end(); 103 gStyle->SetPadTickY(1); << 148 104 << 149 info.fName = it2->second.fName; 105 TGMainFrame *main = new TGMainFrame(gClient << 150 const size_t size2 = it_SOA->second.size(); 106 gTab = new TGTab(main, 200, 200); << 151 info.fG.resize(size2); 107 Double_t timeA, sumG, sumG2; << 152 info.fGerr.resize(size2); 108 Int_t speciesID, number, nEvent; << 153 info.fTime.resize(size2); 109 char speciesName[500]; << 154 110 << 155 Int_t color = (2+_speciesID)%TColor::GetNumberOfColors(); 111 TFile* file = new TFile; << 156 if(color == 5 || color == 10 || color == 0) ++color; 112 file = TFile::Open("scorer.root"); << 157 113 << 158 for(int i2 = 0 ;it2!=end2;++it2, ++i2) 114 TTree* tree = (TTree*)file->Get("species"); << 159 { 115 tree->SetBranchAddress("speciesID", &specie << 160 SpeciesInfoAOS& infoAOS = it2->second; 116 tree->SetBranchAddress("number", &number); << 161 117 tree->SetBranchAddress("nEvent", &nEvent); << 162 Double_t _SumG2 = infoAOS.fG2; 118 tree->SetBranchAddress("speciesName", &spec << 163 Double_t _MeanG = infoAOS.fG/infoAOS.fNEvent; 119 tree->SetBranchAddress("time", &timeA); << 164 Double_t _Gerr = sqrt((_SumG2/infoAOS.fNEvent - pow(_MeanG,2)) 120 tree->SetBranchAddress("sumG", &sumG); << 165 /(infoAOS.fNEvent-1) ); 121 tree->SetBranchAddress("sumG2", &sumG2); << 166 122 << 167 info.fG[i2] = _MeanG; 123 Long64_t nentries = tree->GetEntries(); << 168 info.fGerr[i2] = _Gerr; 124 << 169 info.fTime[i2] = it2->first; 125 if(nentries == 0) { << 170 126 cout << "No entries found in the tree sp << 171 info.fRelatErr += _Gerr/(_MeanG + 1e-30); 127 << file->GetPath() << endl; << 172 if(info.fG[i2] != 0) 128 exit(1); << 173 { 129 } << 174 std::cout<<info.fTime[i2]<<" "<<info.fG[i2]<<" "<<info.fGerr[i2]<<" "<<info.fName<<std::endl; 130 << 175 } 131 std::map<int, std::map<double, SpeciesInfoA << 132 << 133 for (Int_t j=0; j < nentries; j++) { << 134 tree->GetEntry(j); << 135 << 136 SpeciesInfoAOS& infoAOS = speciesTimeInfo << 137 << 138 infoAOS.fNumber += number; << 139 infoAOS.fG += sumG; << 140 infoAOS.fG2 += sumG2; << 141 infoAOS.fNEvent += nEvent; << 142 infoAOS.fName = speciesName; << 143 } << 144 << 145 std::map<Int_t, SpeciesInfoSOA> speciesInfo << 146 << 147 auto it_SOA = speciesTimeInfo.begin(); << 148 auto end_SOA = speciesTimeInfo.end(); << 149 << 150 for (; it_SOA!=end_SOA;++it_SOA) { << 151 const Int_t _speciesID = it_SOA->first; << 152 SpeciesInfoSOA& info = speciesInfo[_spec << 153 << 154 auto it2 = it_SOA->second.begin(); << 155 auto end2 = it_SOA->second.end(); << 156 << 157 info.fName = it2->second.fName; << 158 const size_t size2 = it_SOA->second.size << 159 info.fG.resize(size2); << 160 info.fGerr.resize(size2); << 161 info.fTime.resize(size2); << 162 << 163 Int_t color = (2+_speciesID)%TColor::Get << 164 if(color == 5 || color == 10 || color == << 165 << 166 for (int i2 = 0 ;it2!=end2;++it2, ++i2) << 167 SpeciesInfoAOS& infoAOS = it2->second << 168 << 169 Double_t _SumG2 = infoAOS.fG2; << 170 Double_t _MeanG = infoAOS.fG/infoAOS. << 171 Double_t _Gerr = (infoAOS.fNEvent > 1 << 172 << 173 << 174 info.fG[i2] = _MeanG; << 175 info.fGerr[i2] = _Gerr; << 176 info.fTime[i2] = it2->first; << 177 << 178 info.fRelatErr += _Gerr/(_MeanG + 1e-3 << 179 if(info.fG[i2] != 0) << 180 { << 181 std::cout<<info.fTime[i2]<<" "<<info << 182 } << 183 } 176 } 184 177 185 TGraphErrors* gSpecies = new TGraphError << 178 TGraphErrors* gSpecies = new TGraphErrors(info.fG.size(), 186 << 179 info.fTime.data(), 187 << 180 info.fG.data(), 188 << 181 0, 189 << 182 info.fGerr.data()); 190 << 183 191 TGCompositeFrame *tf = gTab->AddTab(info << 184 TGCompositeFrame *tf = fTab->AddTab(info.fName.c_str()); 192 TGCompositeFrame *frame = new TGComposit << 185 TGCompositeFrame *frame = new TGCompositeFrame(tf, 60, 60, 193 << 186 kHorizontalFrame); 194 << 187 195 tf->AddFrame(frame, new TGLayoutHints(kL << 188 tf->AddFrame(frame, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 196 10 << 189 10,10,10,2)); 197 << 190 198 TRootEmbeddedCanvas *c1 = new TRootEmbed << 191 TRootEmbeddedCanvas *c1 = new TRootEmbeddedCanvas(info.fName.c_str(), 199 << 192 frame, 700, 500); 200 frame->AddFrame(c1, new TGLayoutHints(kL << 193 frame->AddFrame(c1, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 201 10 << 194 10,10,10,2)); 202 c1->GetCanvas()->SetLogx(); << 195 c1->GetCanvas()->SetLogx(); 203 << 196 204 TGHorizontalFrame* hframe = new TGHorizo << 197 TGHorizontalFrame* hframe = new TGHorizontalFrame(tf, 200, 40); 205 << 198 206 TGTextButton* save = new TGTextButton(hf << 199 TGTextButton* save = new TGTextButton(hframe, "&Save as ...", 207 "Sa << 200 "Save()"); 208 hframe->AddFrame(save, new TGLayoutHints << 201 hframe->AddFrame(save, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); 209 << 202 210 TGTextButton *exit = new TGTextButton(hf << 203 TGTextButton *exit = new TGTextButton(hframe, "&Exit ", 211 "g << 204 "gApplication->Terminate()"); 212 hframe->AddFrame(exit, new TGLayoutHints << 205 hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); 213 << 206 214 tf->AddFrame(hframe, new TGLayoutHints(k << 207 tf->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2)); 215 << 208 216 gSpecies->SetTitle(info.fName.c_str()); << 209 gSpecies->SetTitle(info.fName.c_str()); 217 gSpecies->SetMarkerStyle(20+_speciesID); << 210 gSpecies->SetMarkerStyle(20+_speciesID); 218 gSpecies->SetMarkerColor(color); << 211 gSpecies->SetMarkerColor(color); 219 gSpecies->SetLineColor(color); << 212 gSpecies->SetLineColor(color); 220 gSpecies->GetXaxis()->SetTitle("Time (ns << 213 gSpecies->GetXaxis()->SetTitle("Time (ns)"); 221 gSpecies->GetXaxis()->SetTitleOffset(1.1 << 214 gSpecies->GetXaxis()->SetTitleOffset(1.1); 222 gSpecies->GetYaxis()->SetTitle("G value << 215 gSpecies->GetYaxis()->SetTitle("G value (molecules/100 eV)"); 223 gSpecies->GetYaxis()->SetTitleOffset(1.2 << 216 gSpecies->GetYaxis()->SetTitleOffset(1.2); 224 gSpecies->Draw("ALP"); << 217 gSpecies->Draw("ALP"); 225 } << 218 } 226 << 219 227 main->AddFrame(gTab, new TGLayoutHints(kLHi << 220 main->AddFrame(fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | 228 kLHi << 221 kLHintsExpandY, 2, 2, 5, 1)); 229 << 222 230 main->MapSubwindows(); << 223 main->MapSubwindows(); 231 main->Resize(); // resize to default size << 224 main->Resize(); // resize to default size 232 main->MapWindow(); << 225 main->MapWindow(); >> 226 >> 227 } >> 228 >> 229 void Save(){ >> 230 TGFileInfo fi; >> 231 fi.fFileTypes = filetypes; 233 232 >> 233 new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),kFDSave,&fi); >> 234 gROOT->GetListOfCanvases()->At(fTab->GetCurrent())->SaveAs(fi.fFilename); 234 } 235 } 235 236