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