- Timestamp:
- 06/03/02 09:57:00 (22 years ago)
- Location:
- trunk/MagicSoft/Mars/mhist
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/HistLinkDef.h
r1334 r1336 41 41 #pragma link C++ class MHMcEnergyMigration+; 42 42 43 #pragma link C++ class MHCompProb+; 44 #pragma link C++ class MHHadroness+; 43 45 44 46 #endif -
trunk/MagicSoft/Mars/mhist/MFillH.cc
r1334 r1336 243 243 244 244 if (!obj) 245 { 246 if (cls==name) 247 *fLog << inf << "Object '" << fHName << "' not found in parlist... trying to create one." << endl; 245 248 obj = pList->FindCreateObj(cls, name); 249 } 246 250 247 251 if (!obj) -
trunk/MagicSoft/Mars/mhist/MH3.cc
r1334 r1336 319 319 p->Draw("same"); 320 320 p->SetBit(kCanDelete); 321 p->SetDirectory(NULL); 321 322 } 322 323 if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2) … … 325 326 p->Draw("same"); 326 327 p->SetBit(kCanDelete); 328 p->SetDirectory(NULL); 327 329 } 328 330 … … 352 354 p->Draw("same"); 353 355 p->SetBit(kCanDelete); 356 p->SetDirectory(NULL); 354 357 } 355 358 if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2) … … 358 361 p->Draw("same"); 359 362 p->SetBit(kCanDelete); 363 p->SetDirectory(NULL); 360 364 } 361 365 -
trunk/MagicSoft/Mars/mhist/MHMatrix.cc
r1334 r1336 43 43 // 44 44 ///////////////////////////////////////////////////////////////////////////// 45 46 45 #include "MHMatrix.h" 47 46 48 47 #include <TList.h> 48 #include <TArrayD.h> 49 #include <TArrayI.h> 49 50 50 51 #include "MLog.h" … … 61 62 // Default Constructor 62 63 // 63 MHMatrix::MHMatrix( )64 MHMatrix::MHMatrix(const char *name, const char *title) 64 65 : fNumRow(0) 65 66 { 67 fName = name ? name : "MHMatrix"; 68 fTitle = title ? title : "Multidimensional Matrix"; 69 66 70 fData = new TList; 67 71 fData->SetOwner(); 72 73 fRules = new TList; 74 fRules->SetOwner(); 68 75 } 69 76 … … 75 82 { 76 83 delete fData; 84 delete fRules; 77 85 } 78 86 … … 91 99 } 92 100 93 MDataChain &chain = *new MDataChain( name);101 MDataChain &chain = *new MDataChain(rule); 94 102 if (!chain.IsValid()) 95 103 { … … 100 108 101 109 fData->Add(&chain); 110 111 TNamed *name = new TNamed(rule, ""); 112 fRules->Add(name); 113 } 114 115 void MHMatrix::AddColumns(const MHMatrix *matrix) 116 { 117 TIter Next(matrix->fRules); 118 TObject *rule=NULL; 119 while ((rule=Next())) 120 AddColumn(rule->GetName()); 102 121 } 103 122 … … 264 283 { 265 284 int n=0; 266 TIter Next(fData); 285 286 TIter Next(fData->GetSize() ? fData : fRules); 267 287 MData *data = NULL; 268 288 while ((data=(MData*)Next())) 269 289 { 270 *fLog << all << " Column " << setw(3) << n++ << ": " ;290 *fLog << all << " Column " << setw(3) << n++ << ": " << flush; 271 291 data->Print(); 272 292 *fLog << endl; … … 275 295 fM.Print(); 276 296 } 297 298 const TMatrix *MHMatrix::InvertPosDef() 299 { 300 /* 301 ---------------------------------- 302 Substract Mean of Rows from Rows 303 ---------------------------------- 304 305 const Int_t rows = fM.GetNrows(); 306 const Int_t cols = fM.GetNcols(); 307 308 for (int i=0; i<rows; i++) 309 { 310 Double_t mean = 0; 311 for (int j=0; j<cols; j++) 312 mean += fM(i, j); 313 mean /= cols; 314 315 for (int j=0; j<cols; j++) 316 fM(i, j) -= mean; 317 } 318 */ 319 /* 320 ---------------------------------- 321 Substract Mean of Cols from Cols 322 ---------------------------------- 323 324 const Int_t rows = fM.GetNrows(); 325 const Int_t cols = fM.GetNcols(); 326 327 for (int i=0; i<cols; i++) 328 { 329 Double_t mean = 0; 330 for (int j=0; j<rows; j++) 331 mean += fM(j, i); 332 mean /= rows; 333 334 for (int j=0; j<rows; j++) 335 fM(j, i) -= mean; 336 } 337 */ 338 339 TMatrix *m2 = new TMatrix(fM, TMatrix::kTransposeMult, fM); 340 341 Double_t det; 342 m2->Invert(&det); 343 if (det==0) 344 { 345 *fLog << err << "ERROR - MHMatrix::InvertPosDef failed (Matrix is sigular)." << endl; 346 delete m2; 347 return NULL; 348 } 349 350 // m2->Print(); 351 352 return m2; 353 } 354 355 Double_t MHMatrix::CalcDist(const TMatrix &m, const TVector &evt, Int_t num) const 356 { 357 const Int_t rows = fM.GetNrows(); 358 const Int_t cols = fM.GetNcols(); 359 360 TArrayD dists(rows); 361 362 // 363 // Calculate: v^T * M * v 364 // 365 for (int i=0; i<rows; i++) 366 { 367 TVector col(cols); 368 col = TMatrixRow(fM, i); 369 370 TVector d = evt; 371 d -= col; 372 373 TVector d2 = d; 374 d2 *= m; 375 376 dists[i] = fabs(d2*d); 377 } 378 379 TArrayI idx(rows); 380 TMath::Sort(dists.GetSize(), dists.GetArray(), idx.GetArray(), kFALSE); 381 382 const Int_t n = num<rows ? num : rows; 383 384 Double_t res = 0; 385 for (int i=0; i<n; i++) 386 res += dists[idx[i]]; 387 388 return res/n; 389 } 390 391 Double_t MHMatrix::CalcDist(const TVector &evt, Int_t num) 392 { 393 if (!fM2.IsValid()) 394 { 395 const TMatrix &m = *InvertPosDef(); 396 fM2.ResizeTo(m); 397 fM2 = m; 398 delete &m; 399 } 400 401 return CalcDist(fM2, evt, num); 402 } 403 404 void MHMatrix::Reassign() 405 { 406 TMatrix m = fM; 407 fM.ResizeTo(1,1); 408 fM.ResizeTo(m); 409 fM = m; 410 411 TIter Next(fRules); 412 TObject *obj = NULL; 413 while ((obj=Next())) 414 fData->Add(new MDataChain(obj->GetName())); 415 } -
trunk/MagicSoft/Mars/mhist/MHMatrix.h
r1334 r1336 14 14 { 15 15 protected: 16 Int_t fNumRow; // Number of dimensions of histogram16 Int_t fNumRow; //! Number of dimensions of histogram 17 17 TMatrix fM; // Matrix to be filled 18 18 19 TList *fData; // List of data members (columns) 19 TMatrix fM2; //! 20 21 TList *fData; //! List of data members (columns) 22 TList *fRules; // List of data members as text for storage 20 23 21 24 void AddRow(); … … 26 29 27 30 public: 28 MHMatrix( );31 MHMatrix(const char *name=NULL, const char *title=NULL); 29 32 ~MHMatrix(); 30 33 31 34 void AddColumn(const char *name); 35 void AddColumns(const MHMatrix *matrix); 32 36 33 TMatrix &GetM() { return fM; }37 // TMatrix &GetM() { return fM; } 34 38 const TMatrix &GetM() const { return fM; } 39 const TList *GetRules() const { return fRules; } 35 40 36 41 //void Draw(Option_t *opt=NULL); … … 39 44 void Print(Option_t *) const; 40 45 46 const TMatrix *InvertPosDef(); 47 48 Double_t CalcDist(const TMatrix &m, const TVector &v, Int_t num = 25) const; 49 Double_t CalcDist(const TVector &v, Int_t num = 25); 50 51 void Reassign(); 52 41 53 ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events 42 54 }; -
trunk/MagicSoft/Mars/mhist/Makefile
r1334 r1336 48 48 MHTimeDiffTime.cc \ 49 49 MHTimeDiffTheta.cc \ 50 MHCompProb.cc \ 51 MHHadroness.cc \ 50 52 MHMcEnergy.cc \ 51 53 MHMcEfficiency.cc \ … … 53 55 MHMcEfficiencyEnergy.cc \ 54 56 MHMcEnergyImpact.cc \ 57 MHMcEnergyMigration.cc \ 55 58 MHThetabarTime.cc \ 56 59 MHMcRate.cc \
Note:
See TracChangeset
for help on using the changeset viewer.