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

Last change on this file since 2093 was 2093, checked in by moralejo, 23 years ago
*** empty log message ***
File size: 25.8 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@uni-sw.gwdg.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.h> // 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 "MGeomPix.h"
266#include "MGeomCam.h"
267#include "MCerPhotPix.h"
268#include "MCerPhotEvt.h"
269#include "MSigmabar.h"
270
271#include "MGGroupFrame.h" // MGGroupFrame
272
273ClassImp(MImgCleanStd);
274
275enum {
276 kImgCleanLvl1,
277 kImgCleanLvl2
278};
279
280static const TString gsDefName = "MImgCleanStd";
281static const TString gsDefTitle = "Task to perform image cleaning";
282
283// --------------------------------------------------------------------------
284//
285// Default constructor. Here you can specify the cleaning method and levels.
286// If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
287// above mean) are used.
288// Here you can also specify how many rings around the core pixels you want
289// to analyze (with the fixed lvl2). The default value for "rings" is 1.
290//
291MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
292 const char *name, const char *title)
293 : fSgb(NULL), fCleaningMethod(kStandard), fCleanLvl1(lvl1),
294 fCleanLvl2(lvl2), fCleanRings(1)
295
296{
297 fName = name ? name : gsDefName.Data();
298 fTitle = title ? title : gsDefTitle.Data();
299
300 Print();
301}
302
303// --------------------------------------------------------------------------
304//
305// NT 28/04/2003: now the option to use the standard method or the
306// democratic method is implemented:
307//
308// KStandard: This method looks for all pixels with an entry (photons)
309// that is three times bigger than the noise of the pixel
310// (default: 3 sigma, clean level 1)
311// AM 18/11/2002: now cut levels are proportional to the pixel area.
312// In this way the cut corresponds to a fixed
313// phe-density (otherwise, it would bias the images).
314//
315// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
316//
317Int_t MImgCleanStd::CleanStep1Std()
318{
319 const Int_t entries = fEvt->GetNumPixels();
320
321 Int_t max = entries;
322
323 //
324 // check the number of all pixels against the noise level and
325 // set them to 'unused' state if necessary
326 //
327 for (Int_t i=0; i<entries; i++ )
328 {
329 MCerPhotPix &pix = (*fEvt)[i];
330
331 const Int_t id = pix.GetPixId();
332
333 const Float_t entry = pix.GetNumPhotons();
334 const Float_t noise = pix.GetErrorPhot();
335 const Double_t ratio = TMath::Sqrt(fCam->GetPixRatio(id));
336
337 // COBB: '<=' to skip entry=noise=0
338 if (entry * ratio <= fCleanLvl1 * noise)
339 pix.SetPixelUnused();
340
341 if (id>max)
342 max = id;
343 }
344
345 return max;
346}
347
348// --------------------------------------------------------------------------
349//
350// NT 28/04/2003: now the option to use the standard method or the
351// democratic method is implemented:
352//
353// "KDemocratic": this method looks for all pixels with an entry (photons)
354// that is n times bigger than the noise of the mean of the
355// inner pixels (default: 3 sigmabar, clean level 1)
356//
357// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
358//
359Int_t MImgCleanStd::CleanStep1Dem()
360{
361 const Int_t entries = fEvt->GetNumPixels();
362
363 Int_t max = entries;
364
365 //
366 // check the number of all pixels against the noise level and
367 // set them to 'unused' state if necessary
368 //
369 for (Int_t i=0; i<entries; i++ )
370 {
371 MCerPhotPix &pix = (*fEvt)[i];
372
373 const Int_t id = pix.GetPixId();
374
375 const Float_t entry = pix.GetNumPhotons();
376 const Double_t ratio = fCam->GetPixRatio(id);
377
378 // COBB: '<=' to skip entry=noise=0
379 if (entry * ratio <= fCleanLvl1 * fInnerNoise)
380 pix.SetPixelUnused();
381
382 if (id>max)
383 max = id;
384 }
385 return max;
386}
387
388// --------------------------------------------------------------------------
389// The first step of cleaning defines the CORE pixels. All the other pixels
390// are set as UNUSED and belong to RING 0.
391// After this point, only the CORE pixels are set as USED, with RING
392// number 1.
393// Returns the maximum Pixel Id (used for ispixused in CleanStep2)
394//
395Int_t MImgCleanStd::CleanStep1()
396{
397 switch (fCleaningMethod)
398 {
399 case kStandard:
400 return CleanStep1Std();
401 case kDemocratic:
402 return CleanStep1Dem();
403 }
404
405 return 0;
406}
407
408// --------------------------------------------------------------------------
409//
410// Check if the survived pixel have a neighbor, that also
411// survived, otherwise set pixel to unused (removes pixels without
412// neighbors).
413//
414// Takes the maximum pixel id from CleanStep1 as an argument
415//
416void MImgCleanStd::CleanStep2(Int_t max)
417{
418 const Int_t entries = fEvt->GetNumPixels();
419
420 //
421 // In the worst case we have to loop 6 times 577 times, to
422 // catch the behaviour of all next neighbors. Here we can gain
423 // much by using an array instead of checking through all pixels
424 // (MCerPhotEvt::IsPixelUsed) all the time.
425 //
426 Byte_t *ispixused = new Byte_t[max+1];
427
428 for (Int_t i=0; i<entries; i++)
429 {
430 const MCerPhotPix &pix = (*fEvt)[i];
431 ispixused[pix.GetPixId()] = pix.IsPixelUsed() ? 1 : 0 ;
432 }
433
434 for (Int_t i=0; i<entries; i++)
435 {
436 // get entry i from list
437 MCerPhotPix &pix = (*fEvt)[i];
438
439 // get pixel id of this entry
440 const Int_t id = pix.GetPixId();
441
442 // check if pixel is in use, if not goto next pixel in list
443 if (ispixused[id] == 0)
444 continue;
445
446 // check for 'used' neighbors of this pixel
447 const MGeomPix &gpix = (*fCam)[id];
448 const Int_t nnmax = gpix.GetNumNeighbors();
449
450 Bool_t hasNeighbor = kFALSE;
451
452 //loop on the neighbors to check if they are used
453 for (Int_t j=0; j<nnmax; j++)
454 {
455 const Int_t id2 = gpix.GetNeighbor(j);
456
457 // when you find an used neighbor, break the loop
458 if (ispixused[id2] == 1)
459 {
460 hasNeighbor = kTRUE;
461 break;
462 }
463 }
464
465 if (hasNeighbor == kFALSE)
466 pix.SetPixelUnused();
467 }
468
469 delete ispixused;
470
471 //
472 // now we declare all pixels that survive as CorePixels
473 //
474 for (Int_t i=0; i<entries; i++)
475 {
476 MCerPhotPix &pix = (*fEvt)[i];
477
478 if (pix.IsPixelUsed())
479 pix.SetPixelCore();
480 }
481}
482
483// --------------------------------------------------------------------------
484//
485// Look for the boundary pixels around the core pixels
486// if a pixel has more than 2.5 (clean level 2.5) sigma, and
487// a core neigbor it is declared as used.
488//
489Bool_t MImgCleanStd::CleanStep3Std(const MCerPhotPix &pix)
490{
491 //
492 // get pixel id of this entry
493 //
494 const Int_t id = pix.GetPixId();
495
496 //
497 // check the num of photons against the noise level
498 //
499 const Float_t entry = pix.GetNumPhotons();
500 const Float_t noise = pix.GetErrorPhot();
501 const Double_t ratio = TMath::Sqrt(fCam->GetPixRatio(id));
502
503 return (entry * ratio <= fCleanLvl2 * noise);
504}
505
506// --------------------------------------------------------------------------
507//
508// Look for the boundary pixels around the core pixels
509// if a pixel has more than 2.5 (clean level 2.5) sigmabar and
510// a core neighbor, it is declared as used.
511//
512Bool_t MImgCleanStd::CleanStep3Dem(const MCerPhotPix &pix)
513{
514 //
515 // get pixel id of this entry
516 //
517 const Int_t id = pix.GetPixId();
518
519 //
520 // check the num of photons against the noise level
521 //
522 const Float_t entry = pix.GetNumPhotons();
523 const Double_t ratio = fCam->GetPixRatio(id);
524
525 return (entry * ratio <= fCleanLvl2 * fInnerNoise);
526}
527
528void MImgCleanStd::CleanStep3b(MCerPhotPix &pix)
529{
530 const Int_t id = pix.GetPixId();
531
532 //
533 // check if the pixel's next neighbor is a core pixel.
534 // if it is a core pixel set pixel state to: used.
535 //
536 MGeomPix &gpix = (*fCam)[id];
537 const Int_t nnmax = gpix.GetNumNeighbors();
538
539 for (Int_t j=0; j<nnmax; j++)
540 {
541 const Int_t id2 = gpix.GetNeighbor(j);
542
543 if (!fEvt->GetPixById(id2) || !fEvt->IsPixelCore(id2))
544 continue;
545
546 pix.SetPixelUsed();
547 break;
548 }
549}
550
551// --------------------------------------------------------------------------
552//
553// NT: Add option "rings": default value = 1.
554// Look n (n>1) times for the boundary pixels around the used pixels.
555// If a pixel has more than 2.5 (clean level 2.5) sigma,
556// it is declared as used.
557//
558// If a value<2 for fCleanRings is used, no CleanStep4 is done.
559//
560void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
561{
562 //
563 // check if the pixel's next neighbor is a used pixel.
564 // if it is a used pixel set pixel state to: used,
565 // and tell to which ring it belongs to.
566 //
567 const Int_t id = pix.GetPixId();
568 MGeomPix &gpix = (*fCam)[id];
569
570 const Int_t nnmax = gpix.GetNumNeighbors();
571
572 for (Int_t j=0; j<nnmax; j++)
573 {
574 const Int_t id2 = gpix.GetNeighbor(j);
575
576 MCerPhotPix &npix = *fEvt->GetPixById(id2);
577
578 // FIXME!
579 // Needed check to read CT1 data without having a Segmentation fault
580 if (!fEvt->GetPixById(id2))
581 continue;
582
583 if (!npix.IsPixelUsed() || npix.GetRing()>r-1 )
584 continue;
585
586 pix.SetRing(r);
587 break;
588 }
589}
590
591// --------------------------------------------------------------------------
592//
593// Look for the boundary pixels around the core pixels
594// if a pixel has more than 2.5 (clean level 2.5) sigma, and
595// a core neigbor, it is declared as used.
596//
597void MImgCleanStd::CleanStep3()
598{
599 const Int_t entries = fEvt->GetNumPixels();
600
601 for (UShort_t r=1; r<fCleanRings+1; r++)
602 {
603 for (Int_t i=0; i<entries; i++)
604 {
605 //
606 // get pixel as entry il from list
607 //
608 MCerPhotPix &pix = (*fEvt)[i];
609
610 //
611 // if pixel is a core pixel go to the next pixel
612 //
613 if (pix.IsPixelCore())
614 continue;
615
616 switch (fCleaningMethod)
617 {
618 case kStandard:
619 if (CleanStep3Std(pix))
620 continue;
621 break;
622 case kDemocratic:
623 if (CleanStep3Dem(pix))
624 continue;
625 break;
626 }
627
628 if (r==1)
629 CleanStep3b(pix);
630 else
631 CleanStep4(r, pix);
632 }
633 }
634}
635
636// --------------------------------------------------------------------------
637//
638// Check if MEvtHeader exists in the Parameter list already.
639// if not create one and add them to the list
640//
641Bool_t MImgCleanStd::PreProcess (MParList *pList)
642{
643 fCam = (MGeomCam*)pList->FindObject("MGeomCam");
644 if (!fCam)
645 {
646 *fLog << dbginf << "MGeomCam not found (no geometry information available)... aborting." << endl;
647 return kFALSE;
648 }
649
650 fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
651 if (!fEvt)
652 {
653 *fLog << dbginf << "MCerPhotEvt not found... aborting." << endl;
654 return kFALSE;
655 }
656
657 if (fCleaningMethod != kDemocratic)
658 return kTRUE;
659
660 fSgb = (MSigmabar*)pList->FindObject("MSigmabar");
661 if (!fSgb)
662 {
663 *fLog << dbginf << "MSigmabar not found... aborting." << endl;
664 return kFALSE;
665 }
666
667 return kTRUE;
668}
669
670// --------------------------------------------------------------------------
671//
672// Cleans the image.
673//
674Bool_t MImgCleanStd::Process()
675{
676 if (fSgb)
677 fInnerNoise = fSgb->GetSigmabarInner();
678
679 const Int_t max = CleanStep1();
680 CleanStep2(max);
681 CleanStep3();
682
683 return kTRUE;
684}
685
686// --------------------------------------------------------------------------
687//
688// Print descriptor and cleaning levels.
689//
690void MImgCleanStd::Print(Option_t *o) const
691{
692 *fLog << all << GetDescriptor() << " using ";
693 switch (fCleaningMethod)
694 {
695 case kDemocratic:
696 *fLog << "democratic";
697 break;
698 case kStandard:
699 *fLog << "standard";
700 break;
701 }
702 *fLog << " cleaning initialized with noise level " << fCleanLvl1 << " and " << fCleanLvl2;
703 *fLog << " (CleanRings=" << fCleanRings << ")" << endl;
704}
705
706// --------------------------------------------------------------------------
707//
708// Create two text entry fields, one for each cleaning level and a
709// describing text line.
710//
711void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
712{
713 //
714 // Create a frame for line 3 and 4 to be able
715 // to align entry field and label in one line
716 //
717 TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
718 TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
719
720 /*
721 * --> use with root >=3.02 <--
722 *
723
724 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
725 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
726
727 */
728 TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
729 TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
730
731 // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
732 // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
733
734 entry1->SetText("3.0");
735 entry2->SetText("2.5");
736
737 entry1->Associate(f);
738 entry2->Associate(f);
739
740 TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
741 TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
742
743 l1->SetTextJustify(kTextLeft);
744 l2->SetTextJustify(kTextLeft);
745
746 //
747 // Align the text of the label centered, left in the row
748 // with a left padding of 10
749 //
750 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
751 TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
752
753 //
754 // Add one entry field and the corresponding label to each line
755 //
756 f1->AddFrame(entry1);
757 f2->AddFrame(entry2);
758
759 f1->AddFrame(l1, laylabel);
760 f2->AddFrame(l2, laylabel);
761
762 f->AddFrame(f1, layframe);
763 f->AddFrame(f2, layframe);
764
765 f->AddToList(entry1);
766 f->AddToList(entry2);
767 f->AddToList(l1);
768 f->AddToList(l2);
769 f->AddToList(laylabel);
770 f->AddToList(layframe);
771}
772
773// --------------------------------------------------------------------------
774//
775// Process the GUI Events comming from the two text entry fields.
776//
777Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
778{
779 if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
780 return kTRUE;
781
782 TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
783
784 if (!txt)
785 return kTRUE;
786
787 Float_t lvl = atof(txt->GetText());
788
789 switch (param1)
790 {
791 case kImgCleanLvl1:
792 fCleanLvl1 = lvl;
793 *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
794 return kTRUE;
795
796 case kImgCleanLvl2:
797 fCleanLvl2 = lvl;
798 *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
799 return kTRUE;
800 }
801
802 return kTRUE;
803}
804
805// --------------------------------------------------------------------------
806//
807// Implementation of SavePrimitive. Used to write the call to a constructor
808// to a macro. In the original root implementation it is used to write
809// gui elements to a macro-file.
810//
811void MImgCleanStd::StreamPrimitive(ofstream &out) const
812{
813 out << " MImgCleanStd " << GetUniqueName() << "(";
814 out << fCleanLvl1 << ", " << fCleanLvl2;
815
816 if (fName!=gsDefName || fTitle!=gsDefTitle)
817 {
818 out << ", \"" << fName << "\"";
819 if (fTitle!=gsDefTitle)
820 out << ", \"" << fTitle << "\"";
821 }
822 out << ");" << endl;
823
824 if (fCleaningMethod!=kDemocratic)
825 return;
826
827 out << " " << GetUniqueName() << ".SetMethod(MImgCleanStd::kDemocratic);" << endl;
828
829 if (fCleanRings==1)
830 return;
831
832 out << " " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
833}
Note: See TracBrowser for help on using the repository browser.