source: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc@ 2449

Last change on this file since 2449 was 2445, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 26.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Harald Kornmayer, 1/2001
20! Author(s): Nadia Tonello, 4/2003 <mailto:tonello@mppmu.mpg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2003
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MImgCleanStd
30//
31// The Image Cleaning task selects the pixels you use for the Hillas
32// parameters calculation.
33//
34// There are two methods to make the selection: the standard one, as done
35// in the analysis of CT1 data, and the democratic one, as suggested by
36// W.Wittek. The number of photo-electrons of a pixel is compared with the
37// pedestal RMS of the pixel itself (standard method) or with the average
38// RMS of the inner pixels (democratic method).
39// In both cases, the possibility to have a camera with pixels of
40// different area is taken into account.
41// The too noisy pixels can be recognized and eventally switched off
42// (Unmap: set blind pixels to UNUSED) separately, using the
43// MBlindPixelCalc Class. In the MBlindPixelCalc class there is also the
44// function to replace the value of the noisy pixels with the interpolation
45// of the content of the neighbors (SetUseInterpolation).
46//
47// Example:
48// ...
49// MBlindPixelCalc blind;
50// blind.SetUseInterpolation();
51// blind.SetUseBlindPixels();
52//
53// MImgCleanStd clean;
54// ...
55// tlist.AddToList(&blind);
56// tlist.AddToList(&clean);
57//
58// Look at the MBlindPixelCalc Class for more details.
59//
60// Starting point: default values ----------------------------------------
61//
62// When an event is read, before the image cleaning, all the pixels that
63// are in MCerPhotEvt are set as USED and NOT CORE. All the pixels belong
64// to RING number 1 (like USED pixels).
65// Look at MCerPhotPix.h to see how these informations of the pixel are
66// stored.
67// The default cleaning METHOD is the STANDARD one and the number of the
68// rings around the CORE pixel it analyzes is 1. Look at the Constructor
69// of the class in MImgCleanStd.cc to see (or change) the default values.
70//
71// Example: To modify this setting, use the member functions
72// SetMethod(MImgCleanStd::kDemocratic) and SetCleanRings(UShort_t n).
73//
74// MImgCleanStd:CleanStep1 -----------------------------------------------
75//
76// The first step of cleaning defines the CORE pixels. The CORE pixels are
77// the ones which contain the informations about the core of the electro-
78// magnetic shower.
79// The ratio (A_0/A_i) is calculated from fCam->GetPixRatio(i). A_0 is
80// the area of the central pixel of the camera, A_i is the area of the
81// examined pixel. In this way, if we have a MAGIC-like camera, with the
82// outer pixels bigger than the inner ones, the level of cleaning in the
83// two different regions is weighted.
84// This avoids problems of deformations of the shower images.
85// The signal S_i and the pedestal RMS Prms_i of the pixel are called from
86// the object MCerPhotPix.
87// If (default method = kStandard)
88//Begin_Html
89//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/MImgCleanStd-f1.png">
90//End_Html
91// the pixel is set as CORE pixel. L_1 (n=1) is called "first level of
92// cleaning" (default: fCleanLvl1 = 3).
93// All the other pixels are set as UNUSED and belong to RING 0.
94// After this point, only the CORE pixels are set as USED, with RING
95// number 1.
96//
97// MImgCleanStd:CleanStep2 ----------------------------------------------
98//
99// The second step of cleaning looks at the isolated CORE pixels and sets
100// them to UNUSED. An isolated pixel is a pixel without CORE neighbors.
101// At the end of this point, we have set as USED only CORE pixels with at
102// least one CORE neighbor.
103//
104// MImgCleanStd:CleanStep3 ----------------------------------------------
105//
106// The third step of cleaning looks at all the pixels (USED or UNUSED) that
107// surround the USED pixels.
108// If the content of the analyzed pixel survives at the second level of
109// cleaning, i.e. if
110//Begin_Html
111//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/MImgCleanStd-f1.png">
112//End_Html
113// the pixel is set as USED. L_2 (n=2) is called "second level of cleaning"
114// (default:fCleanLvl2 = 2.5).
115//
116// When the number of RINGS to analyze is 1 (default value), only the
117// pixels that have a neighbor CORE pixel are analyzed.
118//
119// There is the option to decide the number of times you want to repeat
120// this procedure (number of RINGS analyzed around the core pixels = n).
121// Every time the level of cleaning is the same (fCleanLvl2) and the pixel
122// will belong to ring r+1, 1 < r < n+1. This is described in
123// MImgCleanStd:CleanStep4 .
124//
125// Dictionary and member functions ---------------------------------------
126//
127// Here there is the detailed description of the member functions and of
128// the terms commonly used in the class.
129//
130// STANDARD CLEANING:
131// =================
132// This is the method used for the CT1 data analysis. It is the default
133// method of the class.
134// The number of photo-electrons of a pixel (S_i) is compared to the
135// pedestal RMS of the pixel itself (Prms_i). To have the comparison to
136// the same photon density for all the pixels, taking into account they
137// can have different areas, we have to keep in mind that the number of
138// photons that hit each pixel, goes linearly with the area of the pixel.
139// The fluctuations of the LONS are proportional to sqrt(A_i), so when we
140// compare S_i with Prms_i, only a factor sqrt(A_0/A_i) is missing to
141// have the same (N.photons/Area) threshold for all the pixels.
142//
143// !!WARNING: if noise independent from the
144// pixel size (example: electronic noise) is introduced,
145// then the noise fluctuations are no longer proportional
146// to sqrt(A_i), and then the cut value (for a camera with
147// pixels of different sizes) resulting from the above
148// procedure would not be proportional to pixel size as we
149// intend. In that case, democratic cleaning is preferred.
150//
151// If
152//Begin_Html
153//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/MImgCleanStd-f1.png">
154//End_Html
155// the pixel survives the cleaning and it is set as CORE (when L_n is the
156// first level of cleaning, fCleanLvl1) or USED (when L_n is the second
157// level of cleaning, fCleanLvl2).
158//
159// Example:
160//
161// MImgCleanStd clean;
162// //creates a default Cleaning object, with default setting
163// ...
164// tlist.AddToList(&clean);
165// // add the image cleaning to the main task list
166//
167// DEMOCRATIC CLEANING:
168// ===================
169// You use this cleaning method when you want to compare the number of
170// photo-electons of each pixel with the average pedestal RMS
171// (fInnerNoise = fSgb->GetSigmabarInner()) of the inner pixels (for the
172// MAGIC camera they are the smaller ones):
173//Begin_Html
174//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/MImgCleanStd-f2.png">
175//End_Html
176// In this case, the simple ratio (A_0/A_i) is used to weight the level of
177// cleaning, because both the inner and the outer pixels (that in MAGIC
178// have a different area) are compared to the same pedestal RMS, coming
179// from the inner pixels.
180// To calculate the average pedestal RMS of the inner pixels, you have to
181// add to the main task list an object of type MSigmabarCalc before the
182// MImgCleanStd object. To know how the calculation of fInnerNoise is done
183// look at the MSigmabarCalc Class.
184//
185// Example:
186//
187// MSigmabarCalc sbcalc;
188// //creates an object that calcutates the average pedestal RMS
189// MImgCleanStd clean;
190// ...
191// tlist.AddToList(&sbcalc);
192// tlist.AddToList(&clean);
193//
194// Member Function: SetMethod()
195// ============================
196// When you call the MImgCleanStd task, the default method is kStandard.
197//
198// If you want to switch to the kDemocratic method you have to
199// call this member function.
200//
201// Example:
202//
203// MImgCleanStd clean;
204// //creates a default Cleaning object, with default setting
205//
206// clean.SetMethod(MImgCleanStd::kDemocratic);
207// //now the method of cleaning is changed to Democratic
208//
209// FIRST AND SECOND CLEANING LEVEL
210// ===============================
211// When you call the MImgCleanStd task, the default cleaning levels are
212// fCleanLvl1 = 3, fCleanLvl2 = 2.5. You can change them easily when you
213// create the MImgCleanStd object.
214//
215// Example:
216//
217// MImgCleanStd clean(Float_t lvl1,Float_t lvl2);
218// //creates a default cleaning object, but the cleaning levels are now
219// //lvl1 and lvl2.
220//
221// RING NUMBER
222// ===========
223// The standard cleaning procedure is such that it looks for the
224// informations of the boundary part of the shower only on the first
225// neighbors of the CORE pixels.
226// There is the possibility now to look not only at the firs neighbors
227// (first ring),but also further away, around the CORE pixels. All the new
228// pixels you can find with this method, are tested with the second level
229// of cleaning and have to have at least an USED neighbor.
230//
231// They will be also set as USED and will be taken into account during the
232// calculation of the image parameters.
233// The only way to distinguish them from the other USED pixels, is the
234// Ring number, that is bigger than 1.
235//
236// Example: You can decide how many rings you want to analyze using:
237//
238// MImgCleanStd clean;
239// //creates a default cleaning object (default number of rings =1)
240// clean.SetCleanRings(UShort_t r);
241// //now it looks r times around the CORE pixels to find new pixels with
242// //signal.
243//
244//
245// Input Containers:
246// MGeomCam, MCerPhotEvt, MSigmabar
247//
248// Output Containers:
249// MCerPhotEvt
250//
251/////////////////////////////////////////////////////////////////////////////
252#include "MImgCleanStd.h"
253
254#include <stdlib.h> // atof
255#include <fstream> // ofstream, SavePrimitive
256
257#include <TGFrame.h> // TGFrame
258#include <TGLabel.h> // TGLabel
259#include <TGTextEntry.h> // TGTextEntry
260
261#include "MLog.h"
262#include "MLogManip.h"
263
264#include "MParList.h"
265#include "MSigmabar.h"
266
267#include "MGeomPix.h"
268#include "MGeomCam.h"
269
270#include "MCerPhotPix.h"
271#include "MCerPhotEvt.h"
272
273#include "MPedestalPix.h"
274#include "MPedestalCam.h"
275
276#include "MGGroupFrame.h" // MGGroupFrame
277
278ClassImp(MImgCleanStd);
279
280using namespace std;
281
282enum {
283 kImgCleanLvl1,
284 kImgCleanLvl2
285};
286
287static const TString gsDefName = "MImgCleanStd";
288static const TString gsDefTitle = "Task to perform image cleaning";
289
290// --------------------------------------------------------------------------
291//
292// Default constructor. Here you can specify the cleaning method and levels.
293// If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
294// above mean) are used.
295// Here you can also specify how many rings around the core pixels you want
296// to analyze (with the fixed lvl2). The default value for "rings" is 1.
297//
298MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
299 const char *name, const char *title)
300 : fSgb(NULL), fCleaningMethod(kStandard), fCleanLvl1(lvl1),
301 fCleanLvl2(lvl2), fCleanRings(1)
302
303{
304 fName = name ? name : gsDefName.Data();
305 fTitle = title ? title : gsDefTitle.Data();
306
307 Print();
308}
309
310// --------------------------------------------------------------------------
311//
312// NT 28/04/2003: now the option to use the standard method or the
313// democratic method is implemented:
314//
315// KStandard: This method looks for all pixels with an entry (photons)
316// that is three times bigger than the noise of the pixel
317// (default: 3 sigma, clean level 1)
318//
319// --------------------------------------------------------------------------
320//
321// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
322//
323void MImgCleanStd::CleanStep1Std()
324{
325 const Int_t entries = fEvt->GetNumPixels();
326
327 //
328 // check the number of all pixels against the noise level and
329 // set them to 'unused' state if necessary
330 //
331
332 for (Int_t i=0; i<entries; i++ )
333 {
334 MCerPhotPix &pix = (*fEvt)[i];
335
336 const Int_t idx = pix.GetPixId();
337
338 const Float_t entry = pix.GetNumPhotons();
339 const Float_t noise = (*fPed)[idx].GetPedestalRms();
340
341 //
342 // We calculate a correction factor which accounts for the
343 // fact that pixels have different size (see TDAS 02-14).
344 //
345 const Double_t factor = TMath::Sqrt(fCam->GetPixRatio(idx));
346
347 // COBB: '<=' to skip entry=noise=0
348 if (entry * factor <= fCleanLvl1 * noise)
349 pix.SetPixelUnused();
350 }
351}
352
353// --------------------------------------------------------------------------
354//
355// NT 28/04/2003: now the option to use the standard method or the
356// democratic method is implemented:
357//
358// "KDemocratic": this method looks for all pixels with an entry (photons)
359// that is n times bigger than the noise of the mean of the
360// inner pixels (default: 3 sigmabar, clean level 1)
361//
362// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
363//
364void MImgCleanStd::CleanStep1Dem()
365{
366 const Int_t entries = fEvt->GetNumPixels();
367
368 //
369 // check the number of all pixels against the noise level and
370 // set them to 'unused' state if necessary
371 //
372 for (Int_t i=0; i<entries; i++ )
373 {
374 MCerPhotPix &pix = (*fEvt)[i];
375
376 const Int_t idx = pix.GetPixId();
377
378 const Float_t entry = pix.GetNumPhotons();
379 const Double_t ratio = fCam->GetPixRatio(idx);
380
381 // COBB: '<=' to skip entry=noise=0
382 if (entry * ratio <= fCleanLvl1 * fInnerNoise)
383 pix.SetPixelUnused();
384 }
385}
386
387// --------------------------------------------------------------------------
388// The first step of cleaning defines the CORE pixels. All the other pixels
389// are set as UNUSED and belong to RING 0.
390// After this point, only the CORE pixels are set as USED, with RING
391// number 1.
392// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
393//
394void MImgCleanStd::CleanStep1()
395{
396 switch (fCleaningMethod)
397 {
398 case kStandard:
399 CleanStep1Std();
400 return;
401 case kDemocratic:
402 CleanStep1Dem();
403 return;
404 }
405}
406
407// --------------------------------------------------------------------------
408//
409// Check if the survived pixel have a neighbor, that also
410// survived, otherwise set pixel to unused (removes pixels without
411// neighbors).
412//
413// Takes the maximum pixel id from CleanStep1 as an argument
414//
415void MImgCleanStd::CleanStep2()
416{
417 const Int_t entries = fEvt->GetNumPixels();
418
419 //
420 // In the worst case we have to loop 6 times 577 times, to
421 // catch the behaviour of all next neighbors. Here we can gain
422 // much by using an array instead of checking through all pixels
423 // (MCerPhotEvt::IsPixelUsed) all the time.
424 //
425 // We allocate the array ourself because the TArrays always do
426 // range check which slows down the access to the array
427 // by 25-50%
428 //
429 Byte_t *ispixused = new Byte_t[fCam->GetNumPixels()];
430 memset(ispixused, 0, sizeof(Byte_t)*fCam->GetNumPixels());
431
432 for (Int_t i=0; i<entries; i++)
433 {
434 const MCerPhotPix &pix = (*fEvt)[i];
435 ispixused[pix.GetPixId()] = pix.IsPixelUsed() ? 1 : 0 ;
436 }
437
438 for (Int_t i=0; i<entries; i++)
439 {
440 // get entry i from list
441 MCerPhotPix &pix = (*fEvt)[i];
442
443 // get pixel id of this entry
444 const Int_t idx = pix.GetPixId();
445
446 // check if pixel is in use, if not goto next pixel in list
447 if (ispixused[idx] == 0)
448 continue;
449
450 // check for 'used' neighbors of this pixel
451 const MGeomPix &gpix = (*fCam)[idx];
452 const Int_t nnmax = gpix.GetNumNeighbors();
453
454 Bool_t hasNeighbor = kFALSE;
455
456 //loop on the neighbors to check if they are used
457 for (Int_t j=0; j<nnmax; j++)
458 {
459 const Int_t idx2 = gpix.GetNeighbor(j);
460
461 // when you find an used neighbor, break the loop
462 if (ispixused[idx2] == 1)
463 {
464 hasNeighbor = kTRUE;
465 break;
466 }
467 }
468
469 if (hasNeighbor == kFALSE)
470 pix.SetPixelUnused();
471 }
472
473 delete ispixused;
474
475 //
476 // now we declare all pixels that survive as CorePixels
477 //
478 for (Int_t i=0; i<entries; i++)
479 {
480 MCerPhotPix &pix = (*fEvt)[i];
481
482 if (pix.IsPixelUsed())
483 pix.SetPixelCore();
484 }
485}
486
487
488// --------------------------------------------------------------------------
489//
490// Look for the boundary pixels around the core pixels
491// if a pixel has more than 2.5 (clean level 2.5) sigma, and
492// a core neigbor it is declared as used.
493//
494Bool_t MImgCleanStd::CleanStep3Std(const MCerPhotPix &pix)
495{
496 //
497 // get pixel id of this entry
498 //
499 const Int_t idx = pix.GetPixId();
500
501 //
502 // check the num of photons against the noise level
503 //
504 const Float_t entry = pix.GetNumPhotons();
505 const Float_t noise = (*fPed)[idx].GetPedestalRms();
506
507 //
508 // We calculate a correction factor which accounts for the
509 // fact that pixels have different size (see TDAS 02-14).
510 //
511 const Double_t factor = TMath::Sqrt(fCam->GetPixRatio(idx));
512
513 return (entry * factor <= fCleanLvl2 * noise);
514}
515
516// --------------------------------------------------------------------------
517//
518// Look for the boundary pixels around the core pixels
519// if a pixel has more than 2.5 (clean level 2.5) sigmabar and
520// a core neighbor, it is declared as used.
521//
522Bool_t MImgCleanStd::CleanStep3Dem(const MCerPhotPix &pix)
523{
524 //
525 // get pixel id of this entry
526 //
527 const Int_t idx = pix.GetPixId();
528
529 //
530 // check the num of photons against the noise level
531 //
532 const Float_t entry = pix.GetNumPhotons();
533 const Double_t ratio = fCam->GetPixRatio(idx);
534
535 return (entry * ratio <= fCleanLvl2 * fInnerNoise);
536}
537
538void MImgCleanStd::CleanStep3b(MCerPhotPix &pix)
539{
540 const Int_t idx = pix.GetPixId();
541
542 //
543 // check if the pixel's next neighbor is a core pixel.
544 // if it is a core pixel set pixel state to: used.
545 //
546 MGeomPix &gpix = (*fCam)[idx];
547 const Int_t nnmax = gpix.GetNumNeighbors();
548
549 for (Int_t j=0; j<nnmax; j++)
550 {
551 const Int_t idx2 = gpix.GetNeighbor(j);
552
553 if (!fEvt->GetPixById(idx2) || !fEvt->IsPixelCore(idx2))
554 continue;
555
556 pix.SetPixelUsed();
557 break;
558 }
559}
560
561// --------------------------------------------------------------------------
562//
563// NT: Add option "rings": default value = 1.
564// Look n (n>1) times for the boundary pixels around the used pixels.
565// If a pixel has more than 2.5 (clean level 2.5) sigma,
566// it is declared as used.
567//
568// If a value<2 for fCleanRings is used, no CleanStep4 is done.
569//
570void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
571{
572 //
573 // check if the pixel's next neighbor is a used pixel.
574 // if it is a used pixel set pixel state to: used,
575 // and tell to which ring it belongs to.
576 //
577 const Int_t idx = pix.GetPixId();
578 MGeomPix &gpix = (*fCam)[idx];
579
580 const Int_t nnmax = gpix.GetNumNeighbors();
581
582 for (Int_t j=0; j<nnmax; j++)
583 {
584 const Int_t idx2 = gpix.GetNeighbor(j);
585
586 MCerPhotPix *npix = fEvt->GetPixById(idx2);
587
588 if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 )
589 continue;
590
591 pix.SetRing(r);
592 break;
593 }
594}
595
596// --------------------------------------------------------------------------
597//
598// Look for the boundary pixels around the core pixels
599// if a pixel has more than 2.5 (clean level 2.5) sigma, and
600// a core neigbor, it is declared as used.
601//
602void MImgCleanStd::CleanStep3()
603{
604 const Int_t entries = fEvt->GetNumPixels();
605
606 for (UShort_t r=1; r<fCleanRings+1; r++)
607 {
608 for (Int_t i=0; i<entries; i++)
609 {
610 //
611 // get pixel as entry il from list
612 //
613 MCerPhotPix &pix = (*fEvt)[i];
614
615 //
616 // if pixel is a core pixel go to the next pixel
617 //
618 if (pix.IsPixelCore())
619 continue;
620
621 switch (fCleaningMethod)
622 {
623 case kStandard:
624 if (CleanStep3Std(pix))
625 continue;
626 break;
627 case kDemocratic:
628 if (CleanStep3Dem(pix))
629 continue;
630 break;
631 }
632
633 if (r==1)
634 CleanStep3b(pix);
635 else
636 CleanStep4(r, pix);
637 }
638 }
639}
640
641// --------------------------------------------------------------------------
642//
643// Check if MEvtHeader exists in the Parameter list already.
644// if not create one and add them to the list
645//
646Int_t MImgCleanStd::PreProcess (MParList *pList)
647{
648 fCam = (MGeomCam*)pList->FindObject("MGeomCam");
649 if (!fCam)
650 {
651 *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
652 return kFALSE;
653 }
654
655 fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
656 if (!fEvt)
657 {
658 *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
659 return kFALSE;
660 }
661
662 if (fCleaningMethod == kDemocratic)
663 {
664 fSgb = (MSigmabar*)pList->FindObject("MSigmabar");
665 if (!fSgb)
666 {
667 *fLog << dbginf << "MSigmabar not found... aborting." << endl;
668 return kFALSE;
669 }
670 }
671 else
672 {
673 fPed = (MPedestalCam*)pList->FindObject("MPedestalCam");
674 if (!fPed)
675 {
676 *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
677 return kFALSE;
678 }
679 }
680
681 return kTRUE;
682}
683
684// --------------------------------------------------------------------------
685//
686// Cleans the image.
687//
688Int_t MImgCleanStd::Process()
689{
690 if (fSgb)
691 fInnerNoise = fSgb->GetSigmabarInner();
692#ifdef DEBUG
693 *fLog << all << "CleanStep 1" << endl;
694#endif
695 CleanStep1();
696#ifdef DEBUG
697 *fLog << all << "CleanStep 2" << endl;
698#endif
699 CleanStep2();
700#ifdef DEBUG
701 *fLog << all << "CleanStep 3" << endl;
702#endif
703 CleanStep3();
704#ifdef DEBUG
705 *fLog << all << "Done." << endl;
706#endif
707
708 return kTRUE;
709}
710
711// --------------------------------------------------------------------------
712//
713// Print descriptor and cleaning levels.
714//
715void MImgCleanStd::Print(Option_t *o) const
716{
717 *fLog << all << GetDescriptor() << " using ";
718 switch (fCleaningMethod)
719 {
720 case kDemocratic:
721 *fLog << "democratic";
722 break;
723 case kStandard:
724 *fLog << "standard";
725 break;
726 }
727 *fLog << " cleaning initialized with noise level " << fCleanLvl1 << " and " << fCleanLvl2;
728 *fLog << " (CleanRings=" << fCleanRings << ")" << endl;
729}
730
731// --------------------------------------------------------------------------
732//
733// Create two text entry fields, one for each cleaning level and a
734// describing text line.
735//
736void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
737{
738 //
739 // Create a frame for line 3 and 4 to be able
740 // to align entry field and label in one line
741 //
742 TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
743 TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
744
745 /*
746 * --> use with root >=3.02 <--
747 *
748
749 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
750 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
751
752 */
753 TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
754 TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
755
756 // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
757 // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
758
759 entry1->SetText("3.0");
760 entry2->SetText("2.5");
761
762 entry1->Associate(f);
763 entry2->Associate(f);
764
765 TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
766 TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
767
768 l1->SetTextJustify(kTextLeft);
769 l2->SetTextJustify(kTextLeft);
770
771 //
772 // Align the text of the label centered, left in the row
773 // with a left padding of 10
774 //
775 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
776 TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
777
778 //
779 // Add one entry field and the corresponding label to each line
780 //
781 f1->AddFrame(entry1);
782 f2->AddFrame(entry2);
783
784 f1->AddFrame(l1, laylabel);
785 f2->AddFrame(l2, laylabel);
786
787 f->AddFrame(f1, layframe);
788 f->AddFrame(f2, layframe);
789
790 f->AddToList(entry1);
791 f->AddToList(entry2);
792 f->AddToList(l1);
793 f->AddToList(l2);
794 f->AddToList(laylabel);
795 f->AddToList(layframe);
796}
797
798// --------------------------------------------------------------------------
799//
800// Process the GUI Events comming from the two text entry fields.
801//
802Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
803{
804 if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
805 return kTRUE;
806
807 TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
808
809 if (!txt)
810 return kTRUE;
811
812 Float_t lvl = atof(txt->GetText());
813
814 switch (param1)
815 {
816 case kImgCleanLvl1:
817 fCleanLvl1 = lvl;
818 *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
819 return kTRUE;
820
821 case kImgCleanLvl2:
822 fCleanLvl2 = lvl;
823 *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
824 return kTRUE;
825 }
826
827 return kTRUE;
828}
829
830// --------------------------------------------------------------------------
831//
832// Implementation of SavePrimitive. Used to write the call to a constructor
833// to a macro. In the original root implementation it is used to write
834// gui elements to a macro-file.
835//
836void MImgCleanStd::StreamPrimitive(ofstream &out) const
837{
838 out << " MImgCleanStd " << GetUniqueName() << "(";
839 out << fCleanLvl1 << ", " << fCleanLvl2;
840
841 if (fName!=gsDefName || fTitle!=gsDefTitle)
842 {
843 out << ", \"" << fName << "\"";
844 if (fTitle!=gsDefTitle)
845 out << ", \"" << fTitle << "\"";
846 }
847 out << ");" << endl;
848
849 if (fCleaningMethod!=kDemocratic)
850 return;
851
852 out << " " << GetUniqueName() << ".SetMethod(MImgCleanStd::kDemocratic);" << endl;
853
854 if (fCleanRings==1)
855 return;
856
857 out << " " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
858}
Note: See TracBrowser for help on using the repository browser.