Changeset 4702 for trunk/MagicSoft/Mars/manalysis
- Timestamp:
- 08/23/04 11:41:30 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/manalysis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
r3734 r4702 31 31 // risk! 32 32 // 33 // Class Version 3: 34 // ---------------- 35 // - added fNumIslands 36 // 33 37 // Class Version 2: 34 38 // ---------------- … … 46 50 #include <fstream> 47 51 52 #include <TArrayD.h> 48 53 #include <TCanvas.h> 49 54 … … 52 57 53 58 #include "MGeomCam.h" 59 #include "MGeomPix.h" 54 60 55 61 ClassImp(MCerPhotEvt); … … 96 102 void MCerPhotEvt::Reset() 97 103 { 98 fNumPixels = 0; 99 fMaxIndex = -1; 104 fNumPixels = 0; 105 fMaxIndex = -1; 106 fNumIslands = -1; 100 107 fLut.Set(0); 101 108 // fPixels->Delete(); … … 346 353 void MCerPhotEvt::RemoveUnusedPixels() 347 354 { 355 // Create iterator 348 356 TIter Next(fPixels); 349 357 MCerPhotPix *pix = NULL; 350 358 359 fMaxIndex = -1; 360 361 // Remove all unused pixels from list, calculate new fMaxIndex 351 362 while ((pix=(MCerPhotPix*)Next())) 363 { 352 364 if (!pix->IsPixelUsed()) 353 365 fPixels->Remove(pix); 354 366 else 367 fMaxIndex = TMath::Max(fMaxIndex, pix->GetPixId()); 368 } 369 370 // Crompress array 355 371 fPixels->Compress(); 372 373 // Get new number of entries in array 356 374 fNumPixels=fPixels->GetEntriesFast(); 375 376 // Rebuild lookup table 377 RebuildLut(); 357 378 } 358 379 … … 409 430 // -------------------------------------------------------------------------- 410 431 // 432 // This function recursively finds all pixels of one island and assigns 433 // the number num as island number to the pixel. 434 // 435 // 1) Check whether a pixel with the index idx exists, is unused 436 // and has not yet a island number assigned. 437 // 2) Assign the island number num to the pixel 438 // 3) Loop over all its neighbors taken from the geometry geom. For all 439 // neighbors recursively call this function (CalcIsland) 440 // 4) Sum the size of the pixel and all neighbors newly assigned 441 // (by CalcIsland) to this island 442 // 443 // Returns the sum of the pixel size. 444 // 445 Double_t MCerPhotEvt::CalcIsland(const MGeomCam &geom, Int_t idx, Int_t num) 446 { 447 // Try to get the pixel information of a pixel with this index 448 MCerPhotPix *pix = GetPixById(idx); 449 450 // If a pixel with this index is not existing... do nothing. 451 if (!pix) 452 return 0; 453 454 // If an island number was already assigned to this pixel... do nothing. 455 if (pix->GetIdxIsland()>=0) 456 return 0; 457 458 // If the pixel is an unused pixel... do nothing. 459 if (!pix->IsPixelUsed()) 460 return 0; 461 462 // Assign the new island number num to this used pixel 463 pix->SetIdxIsland(num); 464 465 // Get the geometry information (neighbors) of this pixel 466 const MGeomPix &gpix = geom[idx]; 467 468 // Get the size of this pixel 469 Double_t size = pix->GetNumPhotons(); 470 471 // Now do the same with all its neighbors and sum the 472 // sizes which they correspond to 473 const Int_t n = gpix.GetNumNeighbors(); 474 for (int i=0; i<n; i++) 475 size += CalcIsland(geom, gpix.GetNeighbor(i), num); 476 477 // return size of this (sub)cluster 478 return size; 479 } 480 481 // -------------------------------------------------------------------------- 482 // 483 // Each pixel which is maked as used is assigned an island number 484 // (starting from 0). A pixel without an island number assigned 485 // has island number -1. 486 // 487 // The index 0 corresponds to the island with the highest size (sum 488 // of GetNumPhotons() in island). The size is decreasing with 489 // increasing indices. 490 // 491 // The information about pixel neighbory is taken from the geometry 492 // MGeomCam geom; 493 // 494 // You can access this island number of a pixel with a call to 495 // MCerPhotPix->GetIdxIsland. The total number of islands available 496 // can be accessed with MCerPhotEvt->GetNumIslands. 497 // 498 // CalcIslands returns the number of islands found. If an error occurs, 499 // eg the geometry has less pixels than the highest index stored, -1 is 500 // returned. 501 // 502 Int_t MCerPhotEvt::CalcIslands(const MGeomCam &geom) 503 { 504 if (fMaxIndex<0 || fNumPixels<=0) 505 { 506 *fLog << err << "ERROR - MCerPhotEvt doesn't contain pixels!" << endl; 507 fNumIslands = 0; 508 return -1; 509 } 510 511 if ((UInt_t)fMaxIndex>=geom.GetNumPixels()) 512 { 513 *fLog << err << "ERROR - MCerPhotEvt::CalcIslands: Size mismatch - geometry too small!" << endl; 514 return -1; 515 } 516 517 // Create a list to hold the sizes of the islands (The maximum 518 // number of islands possible is rougly fNumPixels/4) 519 TArrayD size(fNumPixels/3); 520 521 // Calculate Islands 522 Int_t n=0; 523 524 // We could loop over all indices which looks more straight 525 // forward but should be a lot slower (assuming zero supression) 526 MCerPhotPix *pix=0; 527 528 TIter Next(*this); 529 while ((pix=static_cast<MCerPhotPix*>(Next()))) 530 { 531 // This 'if' is necessary (although it is done in GetIsland, too) 532 // because otherwise the counter (n) would be wrong. 533 // So only 'start' a new island for used pixels (selected by 534 // using the Iterator) which do not yet belong to another island. 535 if (pix->GetIdxIsland()<0) 536 { 537 Double_t sz = CalcIsland(geom, pix->GetPixId(), n); 538 size[n++] = sz; 539 } 540 } 541 542 // Create an array holding the indices 543 TArrayI idx(n); 544 545 // Sort the sizes descending 546 TMath::Sort(n, size.GetArray(), idx.GetArray(), kTRUE); 547 548 // Replace island numbers by size indices -- After this 549 // islands indices are sorted by the island size 550 Next.Reset(); 551 while ((pix=static_cast<MCerPhotPix*>(Next()))) 552 { 553 const Short_t i = pix->GetIdxIsland(); 554 555 // Find new index 556 Short_t j; 557 for (j=0; j<n; j++) 558 if (idx[j]==i) 559 break; 560 561 pix->SetIdxIsland(j==n ? -1 : j); 562 } 563 564 // Now assign number of islands found 565 fNumIslands = n; 566 567 // return number of island 568 return fNumIslands; 569 } 570 571 // -------------------------------------------------------------------------- 572 // 411 573 // Returns, depending on the type flag: 412 574 // … … 416 578 // 3: Number of Photons 417 579 // 4: Error 580 // 5: Island index 418 581 // 419 582 Bool_t MCerPhotEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const … … 442 605 val = pix->GetErrorPhot(); 443 606 break; 607 case 5: 608 val = pix->GetIdxIsland(); 609 break; 444 610 default: 445 611 val = pix->GetNumPhotons()*ratio; -
trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
r3734 r4702 24 24 private: 25 25 UInt_t fNumPixels; 26 Short_t fNumIslands; 26 27 Int_t fMaxIndex; 27 28 TArrayI fLut; // Lookup tabel to lookup pixel by index 28 29 TClonesArray *fPixels; //-> FIXME: Change TClonesArray away from a pointer? 30 31 void RebuildLut() 32 { 33 // Resize Lut 34 fLut.Set(fMaxIndex+1); 35 36 // Reset Lut 37 fLut.Reset(-1); 38 39 // Rebuild Lut 40 for (UInt_t i=0; i<GetNumPixels(); i++) 41 { 42 const MCerPhotPix &pix = (*this)[i]; 43 fLut[pix.GetPixId()] = i; 44 } 45 } 46 47 Double_t CalcIsland(const MGeomCam &geom, Int_t idx, Int_t num); 29 48 30 49 public: … … 32 51 ~MCerPhotEvt() { delete fPixels; } 33 52 34 UInt_t GetNumPixels() const { return fNumPixels; } 35 //void InitSize(UInt_t num) { fPixels->Expand(num); } 53 // Setter function to fill pixels 54 MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0); 55 void FixSize(); 36 56 37 MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0);38 39 void FixSize();57 // Getter functions 58 UInt_t GetNumPixels() const { return fNumPixels; } 59 Short_t GetNumIslands() const { return fNumIslands; }; 40 60 41 61 Bool_t IsPixelExisting(Int_t id) const; … … 52 72 Float_t GetErrorPhotMax(const MGeomCam *geom=NULL) const; 53 73 74 // Getter functions to access single pixels 54 75 MCerPhotPix &operator[](int i) { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); } 55 76 MCerPhotPix &operator[](int i) const { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); } 56 77 78 MCerPhotPix *GetPixById(Int_t idx) const; 79 80 // Functions to change the contained data 57 81 void Scale(Double_t f) { fPixels->ForEach(MCerPhotPix, Scale)(f); } 58 82 void RemoveUnusedPixels(); 83 Int_t CalcIslands(const MGeomCam &geom); 84 void Sort(Int_t upto = kMaxInt) 85 { 86 // Sort pixels by index 87 fPixels->Sort(upto); 88 RebuildLut(); 89 } // For convinience: Sort pixels by index 59 90 60 MCerPhotPix *GetPixById(Int_t idx) const; 61 91 // class MParContainer 62 92 void Reset(); 63 93 94 // class TObject 64 95 void Print(Option_t *opt=NULL) const; 65 96 void Clear(Option_t *opt=NULL) { Reset(); } … … 69 100 void DrawPixelContent(Int_t num) const; 70 101 102 // To build an iterator for this class 71 103 operator TIterator*() const; 72 104 -
trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc
r3751 r4702 45 45 // - added fIsHGSaturated 46 46 // 47 // Version 5: 48 // ---------- 49 // - added fIdxIsland 50 // 47 51 //////////////////////////////////////////////////////////////////////////// 48 52 #include "MCerPhotPix.h" … … 60 64 // 61 65 MCerPhotPix::MCerPhotPix(Int_t pix, Float_t phot, Float_t errphot) : 62 fPixId(pix), fRing(1), fIsCore(kFALSE), fPhot(phot), fErrPhot(errphot), 66 fPixId(pix), fIsCore(kFALSE), fRing(1), fIdxIsland(-1), 67 fPhot(phot), fErrPhot(errphot), 63 68 fIsSaturated(kFALSE), fIsHGSaturated(kFALSE) 64 69 { 65 70 } 71 72 // -------------------------------------------------------------------------- 73 // 74 // From TObject: 75 // Compare abstract method. Must be overridden if a class wants to be able 76 // to compare itself with other objects. Must return -1 if this is smaller 77 // than obj, 0 if objects are equal and 1 if this is larger than obj. 78 // 79 // Here: 80 // Index numbers are compared 81 // 82 Int_t MCerPhotPix::Compare(const TObject *o) const 83 { 84 const Int_t diff = fPixId - static_cast<const MCerPhotPix*>(o)->fPixId; 85 return diff==0 ? 0 : TMath::Sign(1, diff); 86 } 66 87 67 88 // -------------------------------------------------------------------------- -
trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h
r3751 r4702 12 12 Int_t fPixId; // the pixel Id 13 13 14 Short_t fRing; // NT: number of analyzed rings around the core pixels, fRing>0 means: used, fRing= 0 means: unused, fRing= -1 means: unmapped (no possible to use in the calculation of the image parameters) 15 Bool_t fIsCore; // the pixel is a Core pixel -> kTRUE 14 Bool_t fIsCore; // the pixel is a Core pixel -> kTRUE 15 Short_t fRing; // NT: number of analyzed rings around the core pixels, fRing>0 means: used, fRing= 0 means: unused, fRing= -1 means: unmapped (no possible to use in the calculation of the image parameters) 16 Short_t fIdxIsland; // the pixel is a Core pixel -> kTRUE 16 17 17 18 Float_t fPhot; // The number of Cerenkov photons … … 26 27 MCerPhotPix(Int_t pix=-1, Float_t phot=0, Float_t errphot=0); 27 28 28 Int_t 29 Float_t 30 Float_t 29 Int_t GetPixId() const { return fPixId; } 30 Float_t GetNumPhotons() const { return fPhot; } 31 Float_t GetErrorPhot() const { return fErrPhot; } 31 32 32 Bool_t IsPixelUsed() const { return fRing>0; } 33 Bool_t IsPixelUnmapped() const { return fRing==-1; } 34 void SetPixelUnused() { fRing=0; } 35 void SetPixelUsed() { fRing=1; } 36 void SetPixelUnmapped() { fRing=-1;} 33 Bool_t IsPixelUsed() const { return fRing>0; } 34 Bool_t IsPixelUnmapped() const { return fRing==-1; } 35 void SetPixelUnused() { fRing=0; } 36 void SetPixelUsed() { fRing=1; } 37 void SetPixelUnmapped() { fRing=-1;} 38 void SetIdxIsland(Short_t num) { fIdxIsland=num; } 39 Short_t GetIdxIsland() const { return fIdxIsland; } 37 40 38 void 39 Short_t 41 void SetRing(UShort_t r) { fRing = r; } 42 Short_t GetRing() const { return fRing;} 40 43 41 void 42 Bool_t 44 void SetPixelCore() { fIsCore = kTRUE; } 45 Bool_t IsPixelCore() const { return fIsCore; } 43 46 44 void 45 void 46 void 47 void SetNumPhotons(Float_t f) { fPhot = f; } 48 void SetErrorPhot(Float_t f) { fErrPhot = f; } 49 void Set(Float_t np, Float_t ep) { fPhot = np; fErrPhot = ep; } 47 50 48 void 49 Bool_t 51 void SetPixelSaturated() { fIsSaturated = kTRUE; } 52 Bool_t IsPixelSaturated() const { return fIsSaturated; } 50 53 51 void SetPixelHGSaturated(){ fIsHGSaturated = kTRUE; }52 Bool_t IsPixelHGSaturated() const{ return fIsHGSaturated; }54 void SetPixelHGSaturated() { fIsHGSaturated = kTRUE; } 55 Bool_t IsPixelHGSaturated() const { return fIsHGSaturated; } 53 56 54 void 57 void AddNumPhotons(Float_t f) { fPhot += f; } 55 58 56 void 59 void Scale(Float_t f) { fPhot/=f; } 57 60 58 void Print(Option_t *opt = NULL) const; 61 void Print(Option_t *opt = NULL) const; 62 Int_t Compare(const TObject *obj) const; 63 Bool_t IsSortable() const { return kTRUE; } 59 64 60 ClassDef(MCerPhotPix, 4) // class containing information about the Cerenkov Photons in a pixel65 ClassDef(MCerPhotPix, 5) // class containing information about the Cerenkov Photons in a pixel 61 66 }; 62 67
Note:
See TracChangeset
for help on using the changeset viewer.