Changeset 2296 for trunk/MagicSoft
- Timestamp:
- 07/29/03 13:18:57 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 added
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2295 r2296 111 111 - add member function GetSignificance() 112 112 113 * mhist/MHMatrix.cc114 - add MProgressBar in Fill()113 * mhist/MHMatrix.cc 114 - add MProgressBar in Fill() 115 115 116 116 * mmontecarlo/MMcEnergyEst.h -
trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc
r2274 r2296 172 172 for (UShort_t i=0; i<entries; i++) 173 173 { 174 // FIXME: Loop over blinds instead of all pixels!!! 174 175 MCerPhotPix &pix = (*fEvt)[i]; 175 176 … … 203 204 perr[i] += evtpix->GetErrorPhot(); 204 205 // FIXME: perr[i] ??? 206 num++; 205 207 } 206 num++;207 208 } 208 209 -
trunk/MagicSoft/Mars/mbase/MArgs.cc
r2275 r2296 38 38 ClassImp(MArgsEntry); 39 39 ClassImp(MArgs); 40 41 using namespace std; 40 42 41 43 void MArgsEntry::Print(const Option_t *o) const -
trunk/MagicSoft/Mars/mbase/MDirIter.h
r2196 r2296 38 38 AddDirectory(o->GetName(), o->GetTitle()); 39 39 } 40 MDirIter(const char *dir, const char *filter="" ) : fNext(&fList), fDirPtr(NULL)40 MDirIter(const char *dir, const char *filter="", Int_t rec=0) : fNext(&fList), fDirPtr(NULL) 41 41 { 42 42 fList.SetOwner(); 43 AddDirectory(dir, filter );43 AddDirectory(dir, filter, rec); 44 44 } 45 45 ~MDirIter() -
trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
r2247 r2296 125 125 // Add this file as the last entry in the chain 126 126 // 127 void MCT1ReadPreProc::AddFile(const char *txt)127 Int_t MCT1ReadPreProc::AddFile(const char *txt, int) 128 128 { 129 129 const char *name = gSystem->ExpandPathName(txt); … … 135 135 { 136 136 *fLog << warn << "WARNING - Problem reading header... ignored." << endl; 137 return ;137 return 0; 138 138 } 139 139 … … 142 142 { 143 143 *fLog << warn << "WARNING - File contains no data... ignored." << endl; 144 return ;144 return 0; 145 145 } 146 146 … … 150 150 151 151 fFileNames->AddLast(new TNamed(txt, "")); 152 return 1; 152 153 } 153 154 -
trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
r2206 r2296 92 92 ~MCT1ReadPreProc(); 93 93 94 void AddFile(const char *fname);94 Int_t AddFile(const char *fname, int i=0); 95 95 96 96 UInt_t GetEntries() { return fEntries; } -
trunk/MagicSoft/Mars/mfileio/MRead.cc
r2173 r2296 39 39 #include "MLog.h" 40 40 #include "MLogManip.h" 41 42 #include "MDirIter.h" 41 43 42 44 ClassImp(MRead); … … 98 100 return i!=0; 99 101 } 102 103 Int_t MRead::AddFiles(MDirIter &next) 104 { 105 Int_t rc=0; 106 TString n; 107 while (!(n=next()).IsNull()) 108 { 109 const Int_t num = AddFile(n); 110 if (num>0) 111 rc += num; 112 } 113 return rc; 114 } 115 -
trunk/MagicSoft/Mars/mfileio/MRead.h
r2117 r2296 7 7 8 8 class MFilter; 9 class MDirIter; 9 10 10 11 class MRead : public MTask … … 22 23 MFilter *GetSelector() { return fSelector; } 23 24 24 Int_t AddFile(const char *fname, Int_t entries=-1) { return -1; } 25 virtual Int_t AddFile(const char *fname, Int_t entries=-1) { return -1; } 26 Int_t AddFiles(MDirIter &next); 25 27 26 28 Bool_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); -
trunk/MagicSoft/Mars/mfileio/MReadRflFile.cc
r2206 r2296 399 399 // Add this file as the last entry in the chain 400 400 // 401 void MReadRflFile::AddFile(const char *txt)401 Int_t MReadRflFile::AddFile(const char *txt, int) 402 402 { 403 403 const char *name = gSystem->ExpandPathName(txt); … … 424 424 */ 425 425 fFileNames->AddLast(new TNamed(txt, "")); 426 return 1; 426 427 } 427 428 -
trunk/MagicSoft/Mars/mfileio/MReadRflFile.h
r2206 r2296 48 48 ~MReadRflFile(); 49 49 50 void AddFile(const char *fname);50 Int_t AddFile(const char *fname, int i=0); 51 51 52 52 Bool_t Rewind() { fNumFile=0; return kTRUE; } -
trunk/MagicSoft/Mars/mfileio/MReadTree.cc
r2206 r2296 121 121 122 122 if (fname) 123 if (fChain->Add(fname)>0) 124 SetBit(kChainWasChanged); 123 AddFile(fname); 124 // if (fChain->Add(fname)>0) 125 // SetBit(kChainWasChanged); 125 126 } 126 127 … … 586 587 if (!GetEntries()) 587 588 { 588 *fLog << warn << dbginf << "No entries found in file(s)" << endl;589 *fLog << warn << GetDescriptor() << ": No entries found in file(s)" << endl; 589 590 return kFALSE; 590 591 } -
trunk/MagicSoft/Mars/mhist/MH.cc
r2209 r2296 796 796 // Otherwise the present gPad is returned. 797 797 // 798 TVirtualPad *MH::GetNewPad( Option_t *opt)799 { 800 TString str(opt);801 802 if (! str.Contains("nonew", TString::kIgnoreCase))798 TVirtualPad *MH::GetNewPad(TString &opt) 799 { 800 opt.ToLower(); 801 802 if (!opt.Contains("nonew")) 803 803 return NULL; 804 805 opt.ReplaceAll("nonew", ""); 804 806 805 807 return gPad; … … 813 815 TObject *MH::Clone(const char *name) const 814 816 { 815 Bool_t store = TH1::AddDirectoryStatus(); 817 const Bool_t store = TH1::AddDirectoryStatus(); 818 816 819 TH1::AddDirectory(kFALSE); 817 818 820 TObject *o = MParContainer::Clone(name); 819 820 821 TH1::AddDirectory(store); 821 822 … … 831 832 TObject *MH::DrawClone(Option_t *opt, Int_t w, Int_t h) const 832 833 { 833 TVirtualPad *p = GetNewPad(opt); 834 TString option(opt); 835 836 TVirtualPad *p = GetNewPad(option); 834 837 if (!p) 835 838 p = MakeDefCanvas(this, w, h); … … 839 842 gROOT->SetSelectedPad(NULL); 840 843 841 TObject *o = MParContainer::DrawClone(opt );844 TObject *o = MParContainer::DrawClone(option); 842 845 o->SetBit(kCanDelete); 843 846 return o; -
trunk/MagicSoft/Mars/mhist/MH.h
r2150 r2296 75 75 } 76 76 77 static TVirtualPad *GetNewPad( Option_t *opt);77 static TVirtualPad *GetNewPad(TString &opt); 78 78 79 79 static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger); -
trunk/MagicSoft/Mars/mhist/MHHadronness.cc
r2225 r2296 430 430 // -------------------------------------------------------------------------- 431 431 // 432 // Search the hadronness corresponding to a given hadron acceptance. 433 // 434 Double_t MHHadronness::GetHadronness(Double_t acchad) const 435 { 436 for (int i=1; i<fIntPhness->GetNbinsX()+1; i++) 437 if (fIntPhness->GetBinContent(i)>acchad) 438 return fIntPhness->GetBinLowEdge(i); 439 440 return -1; 441 } 442 443 // -------------------------------------------------------------------------- 444 // 432 445 // Print the corresponding Gammas Acceptance for a hadron acceptance of 433 446 // 10%, 20%, 30%, 40% and 50%. Also the minimum distance to the optimum … … 448 461 449 462 *fLog << "Used " << fGhness->GetEntries() << " Gammas and " << fPhness->GetEntries() << " Hadrons." << endl; 450 *fLog << "acc(hadron) acc(gamma) acc(g)/acc(h)" << endl <<endl;451 452 *fLog << " 0.005 " << Form("%6.3f", GetGammaAcceptance(0.005)) << " " << Form("%6.3f", GetGammaAcceptance(0.005)/0.005) << endl;453 *fLog << " 0.02 " << Form("%6.3f", GetGammaAcceptance(0.02)) << " " << Form("%6.3f", GetGammaAcceptance(0.02)/0.02) << endl;454 *fLog << " 0.05 " << Form("%6.3f", GetGammaAcceptance(0.05)) << " " << Form("%6.3f", GetGammaAcceptance(0.05)/0.05) << endl;455 *fLog << " 0.1 " << Form("%6.3f", GetGammaAcceptance(0.1 )) << " " << Form("%6.3f", GetGammaAcceptance(0.1)/0.1) << endl;456 *fLog << " 0.2 " << Form("%6.3f", GetGammaAcceptance(0.2 )) << " " << Form("%6.3f", GetGammaAcceptance(0.2)/0.2) << endl;457 *fLog << " 0.3 " << Form("%6.3f", GetGammaAcceptance(0.3 )) << " " << Form("%6.3f", GetGammaAcceptance(0.3)/0.3) << endl;463 *fLog << "acc(hadron) acc(gamma) acc(g)/acc(h) h" << endl <<endl; 464 465 *fLog << " 0.005 " << Form("%6.3f", GetGammaAcceptance(0.005)) << " " << Form("%6.3f", GetGammaAcceptance(0.005)/0.005) << " " << GetHadronness(0.005) << endl; 466 *fLog << " 0.02 " << Form("%6.3f", GetGammaAcceptance(0.02)) << " " << Form("%6.3f", GetGammaAcceptance(0.02)/0.02) << " " << GetHadronness(0.02) << endl; 467 *fLog << " 0.05 " << Form("%6.3f", GetGammaAcceptance(0.05)) << " " << Form("%6.3f", GetGammaAcceptance(0.05)/0.05) << " " << GetHadronness(0.05) << endl; 468 *fLog << " 0.1 " << Form("%6.3f", GetGammaAcceptance(0.1 )) << " " << Form("%6.3f", GetGammaAcceptance(0.1)/0.1) << " " << GetHadronness(0.1) << endl; 469 *fLog << " 0.2 " << Form("%6.3f", GetGammaAcceptance(0.2 )) << " " << Form("%6.3f", GetGammaAcceptance(0.2)/0.2) << " " << GetHadronness(0.2) << endl; 470 *fLog << " 0.3 " << Form("%6.3f", GetGammaAcceptance(0.3 )) << " " << Form("%6.3f", GetGammaAcceptance(0.3)/0.3) << " " << GetHadronness(0.3) << endl; 458 471 *fLog << Form("%6.3f", GetHadronAcceptance(0.1)) << " 0.1 " << endl; 459 472 *fLog << Form("%6.3f", GetHadronAcceptance(0.2)) << " 0.2 " << endl; -
trunk/MagicSoft/Mars/mhist/MHHadronness.h
r2225 r2296 38 38 Double_t GetGammaAcceptance(Double_t acchad) const; 39 39 Double_t GetHadronAcceptance(Double_t accgam) const; 40 Double_t GetHadronness(Double_t acchad) const; 40 41 41 42 TH1D *Getghness() const { return fGhness; } -
trunk/MagicSoft/Mars/mhist/MHMatrix.cc
r2282 r2296 260 260 return kTRUE; 261 261 } 262 262 263 /* 263 264 // -------------------------------------------------------------------------- … … 503 504 if (!fM2.IsValid()) 504 505 { 506 if (!fM.IsValid()) 507 { 508 *fLog << err << "MHMatrix::CalcDist - ERROR: fM not valid." << endl; 509 return -1; 510 } 511 505 512 const TMatrix *m = InvertPosDef(); 506 513 if (!m) … … 625 632 tlist.AddToList(&fillh); 626 633 627 MProgressBar bar;634 //MProgressBar bar; 628 635 MEvtLoop evtloop; 629 636 evtloop.SetParList(plist); 630 evtloop.SetProgressBar(&bar);637 //evtloop.SetProgressBar(&bar); 631 638 632 639 if (!evtloop.Eventloop()) 633 640 return kFALSE; 634 641 635 tlist.PrintStatistics( 0, kTRUE);642 tlist.PrintStatistics(); 636 643 637 644 plist->Remove(&tlist); … … 1097 1104 void MHMatrix::ShuffleRows(UInt_t seed) 1098 1105 { 1099 TRandom rnd(seed); 1100 1101 for (Int_t irow = 0; irow < fNumRow; irow++) 1102 { 1103 Int_t jrow = rnd.Integer(fNumRow); 1104 1105 for (Int_t icol = 0; icol < fM.GetNcols(); icol++) 1106 { 1107 Real_t tmp = fM(irow,icol); 1108 fM(irow,icol) = fM(jrow,icol); 1109 fM(jrow,icol) = tmp; 1110 } 1111 } 1112 1113 *fLog << warn << this->GetName() << " : Attention! Matrix rows have been shuffled." << endl; 1114 1115 } 1106 TRandom rnd(seed); 1107 1108 TVector v(fM.GetNcols()); 1109 TVector tmp(fM.GetNcols()); 1110 for (Int_t irow = 0; irow<fNumRow; irow++) 1111 { 1112 const Int_t jrow = rnd.Integer(fNumRow); 1113 1114 v = TMatrixRow(fM, irow); 1115 TMatrixRow(fM, irow) = tmp = TMatrixRow(fM, jrow); 1116 TMatrixRow(fM, jrow) = v; 1117 } 1118 1119 *fLog << warn << GetDescriptor() << ": Attention! Matrix rows have been shuffled." << endl; 1120 } 1121 1122 void MHMatrix::ReduceRows(UInt_t num) 1123 { 1124 if ((Int_t)num>=fM.GetNrows()) 1125 { 1126 *fLog << warn << GetDescriptor() << ": Warning - " << num << " >= rows=" << fM.GetNrows() << endl; 1127 return; 1128 } 1129 1130 const TMatrix m(fM); 1131 fM.ResizeTo(num, fM.GetNcols()); 1132 1133 TVector tmp(fM.GetNcols()); 1134 for (UInt_t irow=0; irow<num; irow++) 1135 TMatrixRow(fM, irow) = tmp = TMatrixRow(m, irow); 1136 } -
trunk/MagicSoft/Mars/mhist/MHMatrix.h
r2133 r2296 113 113 114 114 void ShuffleRows(UInt_t seed); 115 void ReduceRows(UInt_t num); 115 116 116 117 ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events -
trunk/MagicSoft/Mars/mimage/ImageLinkDef.h
r2026 r2296 6 6 7 7 #pragma link C++ class MImgCleanStd+; 8 #pragma link C++ class MImgCleanTGB+; 8 9 #pragma link C++ class MCameraSmooth+; 9 10 -
trunk/MagicSoft/Mars/mimage/MCameraSmooth.h
r2209 r2296 29 29 MCameraSmooth(Byte_t cnt=1, const char *name=NULL, const char *title=NULL); 30 30 31 void SetUseCe tralPixel(Bool_t b=kTRUE) { fUseCentralPixel=kTRUE; }31 void SetUseCentralPixel(Bool_t b=kTRUE) { fUseCentralPixel=kTRUE; } 32 32 33 33 ClassDef(MCameraSmooth, 0) // task to smooth the camera contants -
trunk/MagicSoft/Mars/mimage/Makefile
r2179 r2296 29 29 30 30 SRCFILES = MImgCleanStd.cc \ 31 MImgCleanTGB.cc \ 31 32 MCameraSmooth.cc \ 32 33 MHillas.cc \ -
trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
r2274 r2296 840 840 Bool_t MStatusDisplay::HasCanvas(const TCanvas *c) const 841 841 { 842 if (!c) 843 return kFALSE; 844 842 845 if (gROOT->IsBatch()) 843 846 return (Bool_t)fBatch->FindObject(c); -
trunk/MagicSoft/Mars/mranforest/MHRanForest.cc
r2173 r2296 68 68 fGraphSigma = new TGraph; 69 69 fGraphSigma->SetTitle("Evolution of Standard deviation of estimated hadronness in tree combination"); 70 fGraphSigma->SetMaximum(1);71 70 fGraphSigma->SetMarkerStyle(kFullDotSmall); 72 71 } … … 113 112 { 114 113 fNumEvent++; 114 115 115 Double_t hest=0; 116 116 Double_t htrue=fMcEvt->GetPartId()==kGAMMA ? 0. : 1.; … … 124 124 125 125 hest/=i+1; 126 fSigma[i]+=(htrue-hest)*(htrue-hest); 126 127 const Double_t val = htrue-hest; 128 fSigma[i] += val*val; 127 129 } 128 130 … … 145 147 for (Int_t i=0; i<n; i++) 146 148 { 147 Stat_t ip = i+1.;148 fSigma[i] = TMath::Sqrt(fSigma[i]/Stat_t(fNumEvent)); 149 Stat_t ig = fSigma[i];150 max=TMath::Max(max,ig);151 min=TMath::Min(min,ig);152 fGraphSigma->SetPoint(i, ip,ig);149 fSigma[i] = TMath::Sqrt(fSigma[i]/fNumEvent); 150 151 const Stat_t ig = fSigma[i]; 152 if (ig>max) max = ig; 153 if (ig<min) min = ig; 154 fGraphSigma->SetPoint(i, i+1, ig); 153 155 } 156 157 // This is used in root>3.04/? so that SetMaximum/Minimum can succeed 158 fGraphSigma->GetHistogram(); 159 154 160 fGraphSigma->SetMaximum(1.05*max); 155 161 fGraphSigma->SetMinimum(0.95*min); … … 180 186 return; 181 187 182 h->GetXaxis()->SetRangeUser(0,1);188 //h->GetXaxis()->SetRangeUser(0, fNumEvent+1); 183 189 h->SetXTitle("No.of Trees"); 184 190 h->SetYTitle("\\sigma of est.hadronness"); -
trunk/MagicSoft/Mars/mranforest/MHRanForestGini.cc
r2173 r2296 66 66 fGraphGini = new TGraph; 67 67 fGraphGini->SetTitle("Importance of RF-input parameters measured by mean Gini decrease"); 68 fGraphGini->SetMaximum(1);69 68 fGraphGini->SetMarkerStyle(kFullDotSmall); 70 69 } … … 116 115 Bool_t MHRanForestGini::Finalize() 117 116 { 118 Int_t n = fGini.GetSize();117 const Int_t n = fGini.GetSize(); 119 118 120 119 fGraphGini->Set(n); 121 120 122 Stat_t max=0 .;123 Stat_t min=0 .;121 Stat_t max=0; 122 Stat_t min=0; 124 123 for (Int_t i=0; i<n; i++) 125 124 { 126 fGini[i] /=fRanForest->GetNumTrees();127 fGini[i] /=fRanForest->GetNumData();125 fGini[i] /= fRanForest->GetNumTrees(); 126 fGini[i] /= fRanForest->GetNumData(); 128 127 129 Stat_t ip = i+1.;130 Stat_t ig = fGini[i];128 const Stat_t ip = i+1; 129 const Stat_t ig = fGini[i]; 131 130 132 max=TMath::Max(max,ig);133 min=TMath::Min(min,ig);131 if (ig>max) max=ig; 132 if (ig<min) min=ig; 134 133 135 134 fGraphGini->SetPoint(i,ip,ig); 136 135 } 136 137 // This is used in root>3.04/? so that SetMaximum/Minimum can succeed 138 fGraphGini->GetHistogram(); 139 137 140 fGraphGini->SetMaximum(1.05*max); 138 141 fGraphGini->SetMinimum(0.95*min); … … 163 166 return; 164 167 165 h->GetXaxis()->SetRangeUser(0,1);168 //h->GetXaxis()->SetRangeUser(0, fGini.GetSize()+1); 166 169 h->SetXTitle("No.of RF-input parameter"); 167 170 h->SetYTitle("Mean decrease in Gini-index [a.u.]"); -
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r2173 r2296 103 103 Int_t ntree=0; 104 104 105 TIter forest(fForest);105 TIter Next(fForest); 106 106 107 107 MRanTree *tree; 108 while ((tree=(MRanTree*) forest.Next()))108 while ((tree=(MRanTree*)Next())) 109 109 { 110 110 fTreeHad[ntree]=tree->TreeHad(event); … … 112 112 ntree++; 113 113 } 114 return hadroness/ Double_t(ntree);114 return hadroness/ntree; 115 115 } 116 116 … … 190 190 Bool_t MRanForest::GrowForest() 191 191 { 192 Int_t ninbag=0; 193 TArrayI datsortinbag; 194 TArrayF classpopw; 195 TArrayI jinbag; 196 TArrayF winbag; 197 198 jinbag.Set(fNumData); 199 winbag.Set(fNumData); 200 classpopw.Set(2); 201 202 TMatrix hadrons=fHadrons->GetM(); 203 TMatrix gammas=fGammas->GetM(); 192 if(!gRandom) 193 { 194 *fLog << err << dbginf << "gRandom not initialized... aborting." << endl; 195 return kFALSE; 196 } 204 197 205 198 fTreeNo++; 206 199 207 200 // initialize running output 208 if(fTreeNo==1) 209 { 210 cout<<endl<<endl<<"1st col.: no. of tree"<<endl; 211 cout<<"2nd col.: error in % (calulated using oob-data -> overestim. of error)"<<endl; 212 } 213 214 jinbag.Reset(); 215 classpopw.Reset(); 216 winbag.Reset(); 201 if (fTreeNo==1) 202 { 203 *fLog << inf << endl; 204 *fLog << underline; // << "1st col 2nd col" << endl; 205 *fLog << "no. of tree error in % (calulated using oob-data -> overestim. of error)" << endl; 206 } 207 208 TArrayF classpopw(2); 209 TArrayI jinbag(fNumData); // Initialization includes filling with 0 210 TArrayF winbag(fNumData); // Initialization includes filling with 0 217 211 218 212 // bootstrap aggregating (bagging) -> sampling with replacement: … … 221 215 // {0,1,...,fNumData-1}, which is the set of the index numbers of 222 216 // all events in the training sample 223 224 for (Int_t n=0;n<fNumData;n++) 225 { 226 if(!gRandom) 227 { 228 *fLog << err << dbginf << "gRandom not initialized... aborting." << endl; 229 return kFALSE; 230 } 231 232 Int_t k=Int_t(fNumData*gRandom->Rndm()); 217 for (Int_t n=0; n<fNumData; n++) 218 { 219 const Int_t k = Int_t(gRandom->Rndm()*fNumData); 233 220 234 221 classpopw[fHadTrue[k]]+=fWeight[k]; … … 241 228 // In bagging procedure ca. 2/3 of all elements in the original 242 229 // training sample are used to build the in-bag data 243 datsortinbag=fDataSort; 244 245 ModifyDataSort(datsortinbag,ninbag,jinbag); 230 TArrayI datsortinbag=fDataSort; 231 Int_t ninbag=0; 232 233 ModifyDataSort(datsortinbag, ninbag, jinbag); 234 235 const TMatrix &hadrons=fHadrons->GetM(); 236 const TMatrix &gammas =fGammas->GetM(); 246 237 247 238 // growing single tree … … 258 249 // determined from oob-data is underestimated, but can still be taken as upper limit. 259 250 260 TVector event(fNumDim); 261 for(Int_t ievt=0;ievt<fNumHad;ievt++) 262 { 263 if(jinbag[ievt]>0)continue; 264 event=TMatrixRow(hadrons,ievt); 265 fHadEst[ievt]+=fRanTree->TreeHad(event); 251 for (Int_t ievt=0;ievt<fNumHad;ievt++) 252 { 253 if (jinbag[ievt]>0) 254 continue; 255 fHadEst[ievt] += fRanTree->TreeHad(hadrons, ievt); 266 256 fNTimesOutBag[ievt]++; 267 257 } 268 for (Int_t ievt=0;ievt<fNumGam;ievt++)269 { 270 if (jinbag[fNumHad+ievt]>0)continue;271 event=TMatrixRow(gammas,ievt);272 fHadEst[fNumHad+ievt] +=fRanTree->TreeHad(event);258 for (Int_t ievt=0;ievt<fNumGam;ievt++) 259 { 260 if (jinbag[fNumHad+ievt]>0) 261 continue; 262 fHadEst[fNumHad+ievt] += fRanTree->TreeHad(gammas, ievt); 273 263 fNTimesOutBag[fNumHad+ievt]++; 274 264 } 275 265 276 266 Int_t n=0; 277 fErr=0;278 for (Int_t ievt=0;ievt<fNumData;ievt++)279 if (fNTimesOutBag[ievt]!=0)267 Double_t ferr=0; 268 for (Int_t ievt=0;ievt<fNumData;ievt++) 269 if (fNTimesOutBag[ievt]!=0) 280 270 { 281 fErr+=TMath::Power(fHadEst[ievt]/fNTimesOutBag[ievt]-fHadTrue[ievt],2.); 271 const Double_t val = fHadEst[ievt]/fNTimesOutBag[ievt]-fHadTrue[ievt]; 272 ferr += val*val; 282 273 n++; 283 274 } 284 275 285 fErr/=Float_t(n); 286 fErr=TMath::Sqrt(fErr); 276 ferr = TMath::Sqrt(ferr/n); 287 277 288 278 // give running output 289 cout << setw(5) << fTreeNo << setw(15) << Form("%.2f",100.*fErr) << endl;279 *fLog << inf << setw(5) << fTreeNo << Form("%15.2f", ferr*100) << endl; 290 280 291 281 // adding tree to forest 292 282 AddTree(); 293 283 294 return (fTreeNo<fNumTrees);284 return fTreeNo<fNumTrees; 295 285 } 296 286 … … 315 305 TArrayI isort(fNumData); 316 306 317 TMatrixhadrons=fHadrons->GetM();318 TMatrixgammas=fGammas->GetM();307 const TMatrix &hadrons=fHadrons->GetM(); 308 const TMatrix &gammas=fGammas->GetM(); 319 309 320 310 for (Int_t j=0;j<fNumHad;j++) … … 346 336 for(Int_t n=0;n<fNumData-1;n++) 347 337 { 348 Int_t n1=isort[n]; 349 Int_t n2=isort[n+1]; 338 const Int_t n1=isort[n]; 339 const Int_t n2=isort[n+1]; 340 350 341 fDataSort[mvar*fNumData+n]=n1; 351 342 if(n==0) fDataRang[mvar*fNumData+n1]=0; … … 359 350 fDataSort[(mvar+1)*fNumData-1]=isort[fNumData-1]; 360 351 } 361 362 return; 363 } 364 365 void MRanForest::ModifyDataSort(TArrayI &datsortinbag,Int_t ninbag,TArrayI &jinbag) 352 } 353 354 void MRanForest::ModifyDataSort(TArrayI &datsortinbag, Int_t ninbag, const TArrayI &jinbag) 366 355 { 367 356 ninbag=0; … … 394 383 } 395 384 } 396 return;397 385 } 398 386 -
trunk/MagicSoft/Mars/mranforest/MRanForest.h
r2114 r2296 65 65 // estimates for classification error of growing forest 66 66 TArrayD fTreeHad; 67 Float_t fErr;68 67 69 68 protected: 70 69 // create and modify (->due to bagging) fDataSort 71 70 void CreateDataSort(); 72 void ModifyDataSort(TArrayI &datsortinbag, Int_t ninbag,TArrayI &jinbag);71 void ModifyDataSort(TArrayI &datsortinbag, Int_t ninbag, const TArrayI &jinbag); 73 72 74 73 public: -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r2207 r2296 84 84 // Needs: 85 85 // - MatrixGammas [MHMatrix] 86 // - MatrixHadrons {MHMatrix]86 // - MatrixHadrons [MHMatrix] 87 87 // - MHadronness 88 88 // - all data containers used to build the matrixes -
trunk/MagicSoft/Mars/mranforest/MRanTree.cc
r2173 r2296 76 76 } 77 77 78 void MRanTree::GrowTree( TMatrix &mhad,TMatrix &mgam,Int_t numdata, Int_t numdim,TArrayI &hadtrue,78 void MRanTree::GrowTree(const TMatrix &mhad, const TMatrix &mgam,Int_t numdata, Int_t numdim,TArrayI &hadtrue, 79 79 TArrayI &datasort,TArrayI &datarang,TArrayF &tclasspop,TArrayI &jinbag, 80 80 TArrayF &winbag,TArrayF &weight) … … 88 88 for (Int_t n=0;n<numdata;n++) 89 89 if(jinbag[n]==1) ninbag++; 90 91 // weighted class populations after split92 TArrayF wl(2); // left node93 TArrayF wc(2);94 TArrayF wr(2); // right node95 TArrayI nc(2);96 90 97 91 TArrayI bestsplit(nrnodes); … … 106 100 TArrayI idmove(numdata); 107 101 108 idmove.Reset();109 110 102 fBestVar.Set(nrnodes); 111 103 fTreeMap1.Set(nrnodes); … … 123 115 BuildTree(datasort,datarang,hadtrue,numdim,numdata,bestsplit, 124 116 bestsplitnext,nodepop,nodestart,tclasspop,nrnodes, 125 idmove,ncase,parent,jinbag,iv,winbag, wr,wc,wl,ninbag);117 idmove,ncase,parent,jinbag,iv,winbag,ninbag); 126 118 127 119 // post processing, determine cut (or split) values fBestSplit 128 120 Int_t nhad=mhad.GetNrows(); 129 121 130 for(Int_t k=0; k<nrnodes;k++)131 { 132 Int_t bsp=bestsplit[k];133 Int_t bspn=bestsplitnext[k];134 Int_t msp=fBestVar[k]; 135 136 if (GetNodeStatus(k)!=-1)137 {138 fBestSplit[k] = bsp<nhad ? mhad(bsp,msp):mgam(bsp-nhad,msp); 139 fBestSplit[k] += bspn<nhad ? mhad(bspn,msp):mgam(bspn-nhad,msp);140 fBestSplit[k] /=2.;141 }122 for(Int_t k=0; k<nrnodes; k++) 123 { 124 if (GetNodeStatus(k)==-1) 125 continue; 126 127 const Int_t &bsp =bestsplit[k]; 128 const Int_t &bspn=bestsplitnext[k]; 129 const Int_t &msp =fBestVar[k]; 130 131 fBestSplit[k] = bsp<nhad ? mhad(bsp, msp):mgam(bsp-nhad, msp); 132 fBestSplit[k] += bspn<nhad ? mhad(bspn,msp):mgam(bspn-nhad,msp); 133 fBestSplit[k] /= 2; 142 134 } 143 135 … … 152 144 Int_t numdata,Int_t ndstart,Int_t ndend,TArrayF &tclasspop, 153 145 Int_t &msplit,Float_t &decsplit,Int_t &nbest,TArrayI &ncase, 154 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,TArrayF &wr, 155 TArrayF &wc,TArrayF &wl,Int_t kbuild) 156 { 146 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t kbuild) 147 { 148 if(!gRandom) 149 { 150 *fLog << err << dbginf << "gRandom not initialized... aborting." << endl; 151 return kFALSE; 152 } 153 154 // weighted class populations after split 155 TArrayF wc(2); 156 TArrayF wr(2); // right node 157 157 158 // For the best split, msplit is the index of the variable (e.g Hillas par., zenith angle ,...) 158 159 // split on. decsplit is the decreae in impurity measured by Gini-index. … … 160 161 // and nsplitnext is the case number of the next larger value of msplit. 161 162 162 Int_t mvar,nc,nbestvar=0,jstat,k;163 Float_t crit ,crit0,critmax,critvar=0;163 Int_t nc,nbestvar=0,k; 164 Float_t crit; 164 165 Float_t rrn, rrd, rln, rld, u; 165 166 … … 171 172 for (Int_t j=0;j<2;j++) 172 173 { 173 pno+=tclasspop[j]*tclasspop[j]; 174 pdo+=tclasspop[j]; 175 } 176 crit0=pno/pdo; 177 jstat=0; 174 pno+=tclasspop[j]*tclasspop[j]; 175 pdo+=tclasspop[j]; 176 } 177 178 const Double_t crit0=pno/pdo; 179 Int_t jstat=0; 178 180 179 181 // start main loop through variables to find best split, 180 182 // (Gini-index as criterium crit) 181 183 182 critmax=-1.0e20; // FIXME: Replace by a constant from limits.h184 Double_t critmax=-1.0e20; // FIXME: Replace by a constant from limits.h 183 185 184 186 // random split selection, number of trials = fNumTry 185 if(!gRandom)186 {187 *fLog << err << dbginf << "gRandom not initialized... aborting." << endl;188 return kFALSE;189 }190 187 for(Int_t mt=0;mt<fNumTry;mt++) 191 188 { 192 mvar=Int_t(mdim*gRandom->Rndm());189 Int_t mvar=Int_t(gRandom->Rndm()*mdim); 193 190 194 191 // Gini index = rrn/rrd+rln/rld … … 197 194 rln=0; 198 195 rld=0; 199 wl.Reset(); 200 201 for (Int_t j=0;j<2;j++) 202 { 203 wr[j]=tclasspop[j]; 204 } 205 206 critvar=-1.0e20; 196 197 TArrayF wl(2); // left node 198 wr = tclasspop; 199 200 Double_t critvar=-1.0e20; 207 201 208 202 for(Int_t nsp=ndstart;nsp<=ndend-1;nsp++) … … 223 217 if (datarang[mvar*numdata+nc]<datarang[mvar*numdata+datasort[mvar*numdata+nsp+1]]) 224 218 { 225 if (TMath::Min(rrd,rld)>1.0e-5)219 if (TMath::Min(rrd,rld)>1.0e-5) 226 220 { 227 221 crit=(rln/rld)+(rrn/rrd); … … 309 303 TArrayI &nodepop,TArrayI &nodestart,TArrayF &tclasspop, 310 304 Int_t nrnodes,TArrayI &idmove,TArrayI &ncase,TArrayI &parent, 311 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,TArrayF &wr,TArrayF &wc, 312 TArrayF &wl,Int_t ninbag) 305 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t ninbag) 313 306 { 314 307 // Buildtree consists of repeated calls to two void functions, FindBestSplit and MoveData. … … 326 319 // returns. 327 320 328 Int_t msplit, nbest,ndendl,nc,jstat,ndend,ndstart;321 Int_t msplit, nbest, ndendl; 329 322 Float_t decsplit=0; 330 Float_t popt1,popt2,pp; 331 TArrayF classpop; 332 TArrayI nodestatus; 333 334 nodestatus.Set(nrnodes); 335 classpop.Set(2*nrnodes); 336 337 nodestatus.Reset(); 323 TArrayF classpop(2*nrnodes); 324 TArrayI nodestatus(nrnodes); 325 338 326 nodestart.Reset(); 339 327 nodepop.Reset(); 340 classpop.Reset();341 342 328 343 329 for (Int_t j=0;j<2;j++) … … 357 343 // initialize for next call to FindBestSplit 358 344 359 ndstart=nodestart[kbuild];360 ndend=ndstart+nodepop[kbuild]-1;345 const Int_t ndstart=nodestart[kbuild]; 346 const Int_t ndend=ndstart+nodepop[kbuild]-1; 361 347 for (Int_t j=0;j<2;j++) 362 348 tclasspop[j]=classpop[j*nrnodes+kbuild]; 363 349 364 jstat=FindBestSplit(datasort,datarang,hadtrue,mdim,numdata, 365 ndstart,ndend,tclasspop,msplit,decsplit, 366 nbest,ncase,jinbag,iv,winbag,wr,wc,wl, 367 kbuild); 350 const Int_t jstat=FindBestSplit(datasort,datarang,hadtrue,mdim,numdata, 351 ndstart,ndend,tclasspop,msplit,decsplit, 352 nbest,ncase,jinbag,iv,winbag,kbuild); 368 353 369 354 if(jstat==1) { … … 392 377 for (Int_t n=ndstart;n<=ndendl;n++) 393 378 { 394 nc=ncase[n];395 Int_t j=hadtrue[nc];379 const Int_t nc=ncase[n]; 380 const Int_t j=hadtrue[nc]; 396 381 classpop[j*nrnodes+ncur+1]+=winbag[nc]; 397 382 } … … 399 384 for (Int_t n=ndendl+1;n<=ndend;n++) 400 385 { 401 nc=ncase[n];402 Int_t j=hadtrue[nc];386 const Int_t nc=ncase[n]; 387 const Int_t j=hadtrue[nc]; 403 388 classpop[j*nrnodes+ncur+2]+=winbag[nc]; 404 389 } … … 410 395 if (nodepop[ncur+1]<=fNdSize) nodestatus[ncur+1]=-1; 411 396 if (nodepop[ncur+2]<=fNdSize) nodestatus[ncur+2]=-1; 412 popt1=0; 413 popt2=0; 397 398 Double_t popt1=0; 399 Double_t popt2=0; 414 400 for (Int_t j=0;j<2;j++) 415 401 { 416 popt1+=classpop[j*nrnodes+ncur+1];417 popt2+=classpop[j*nrnodes+ncur+2];402 popt1+=classpop[j*nrnodes+ncur+1]; 403 popt2+=classpop[j*nrnodes+ncur+2]; 418 404 } 419 405 420 406 for (Int_t j=0;j<2;j++) 421 407 { 422 if (classpop[j*nrnodes+ncur+1]==popt1) nodestatus[ncur+1]=-1;423 if (classpop[j*nrnodes+ncur+2]==popt2) nodestatus[ncur+2]=-1;408 if (classpop[j*nrnodes+ncur+1]==popt1) nodestatus[ncur+1]=-1; 409 if (classpop[j*nrnodes+ncur+2]==popt2) nodestatus[ncur+2]=-1; 424 410 } 425 411 … … 446 432 { 447 433 fNumEndNodes++; 448 pp=0;434 Double_t pp=0; 449 435 for (Int_t j=0;j<2;j++) 450 436 { … … 482 468 483 469 const Int_t m=fBestVar[kt]; 484 485 470 kt = event(m)<=fBestSplit[kt] ? fTreeMap1[kt] : fTreeMap2[kt]; 486 471 } 487 472 488 473 return fBestSplit[kt]; 474 } 475 476 Double_t MRanTree::TreeHad(const TMatrixRow &event) 477 { 478 Int_t kt=0; 479 // to optimize on storage space node status and node class 480 // are coded into fBestVar: 481 // status of node kt = TMath::Sign(1,fBestVar[kt]) 482 // class of node kt = fBestVar[kt]+2 (class defined by larger 483 // node population, actually not used) 484 // hadronness assigned to node kt = fBestSplit[kt] 485 486 for (Int_t k=0;k<fNumNodes;k++) 487 { 488 if (fBestVar[kt]<0) 489 break; 490 491 const Int_t m=fBestVar[kt]; 492 kt = event(m)<=fBestSplit[kt] ? fTreeMap1[kt] : fTreeMap2[kt]; 493 } 494 495 return fBestSplit[kt]; 496 } 497 498 Double_t MRanTree::TreeHad(const TMatrix &m, Int_t ievt) 499 { 500 return TreeHad(TMatrixRow(m, ievt)); 489 501 } 490 502 -
trunk/MagicSoft/Mars/mranforest/MRanTree.h
r2114 r2296 15 15 16 16 class TMatrix; 17 class TMatrixRow; 17 18 class TVector; 18 19 class TRandom; … … 60 61 61 62 // functions used in tree growing process 62 void GrowTree(TMatrix &mhad,TMatrix &mgam,Int_t numdata, Int_t numdim,TArrayI &hadtrue, 63 void GrowTree(const TMatrix &mhad, const TMatrix &mgam,Int_t numdata, 64 Int_t numdim,TArrayI &hadtrue, 63 65 TArrayI &datasort,TArrayI &datarang,TArrayF &tclasspop,TArrayI &jinbag, 64 66 TArrayF &winbag,TArrayF &weight); … … 67 69 Int_t numdata,Int_t ndstart,Int_t ndend,TArrayF &tclasspop, 68 70 Int_t &msplit,Float_t &decsplit,Int_t &nbest,TArrayI &ncase, 69 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,TArrayF &wr, 70 TArrayF &wc,TArrayF &wl,Int_t kbuild); 71 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t kbuild); 71 72 72 73 void MoveData(TArrayI &datasort,Int_t mdim,Int_t numdata,Int_t ndstart, … … 78 79 TArrayI &nodepop,TArrayI &nodestart,TArrayF &tclasspop, 79 80 Int_t nrnodes,TArrayI &idmove,TArrayI &ncase,TArrayI &parent, 80 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,TArrayF &wr,TArrayF &wc, 81 TArrayF &wl,Int_t ninbag); 81 TArrayI &jinbag,TArrayI &iv,TArrayF &winbag,Int_t ninbag); 82 82 83 83 Double_t TreeHad(const TVector &event); 84 Double_t TreeHad(const TMatrixRow &event); 85 Double_t TreeHad(const TMatrix &m, Int_t ievt); 84 86 Double_t TreeHad(); 85 87
Note:
See TracChangeset
for help on using the changeset viewer.