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

Last change on this file since 4787 was 4717, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 26.0 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//
131// STANDARD CLEANING:
132// =================
133// This is the method used for the CT1 data analysis. It is the default
134// method of the class.
135// The number of photo-electrons of a pixel (S_i) is compared to the
136// pedestal RMS of the pixel itself (Prms_i). To have the comparison to
137// the same photon density for all the pixels, taking into account they
138// can have different areas, we have to keep in mind that the number of
139// photons that hit each pixel, goes linearly with the area of the pixel.
140// The fluctuations of the LONS are proportional to sqrt(A_i), so when we
141// compare S_i with Prms_i, only a factor sqrt(A_0/A_i) is missing to
142// have the same (N.photons/Area) threshold for all the pixels.
143//
144// !!WARNING: if noise independent from the
145// pixel size (example: electronic noise) is introduced,
146// then the noise fluctuations are no longer proportional
147// to sqrt(A_i), and then the cut value (for a camera with
148// pixels of different sizes) resulting from the above
149// procedure would not be proportional to pixel size as we
150// intend. In that case, democratic cleaning is preferred.
151//
152// If
153//Begin_Html
154//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/MImgCleanStd-f1.png">
155//End_Html
156// the pixel survives the cleaning and it is set as CORE (when L_n is the
157// first level of cleaning, fCleanLvl1) or USED (when L_n is the second
158// level of cleaning, fCleanLvl2).
159//
160// Example:
161//
162// MImgCleanStd clean;
163// //creates a default Cleaning object, with default setting
164// ...
165// tlist.AddToList(&clean);
166// // add the image cleaning to the main task list
167//
168//
169// DEMOCRATIC CLEANING:
170// ===================
171// You use this cleaning method when you want to compare the number of
172// photo-electons of each pixel with the average pedestal RMS of the
173// inner pixels (for the MAGIC camera they are the smaller ones):
174//Begin_Html
175//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/MImgCleanStd-f2.png">
176//End_Html
177// In this case, the simple ratio (A_0/A_i) is used to weight the level of
178// cleaning, because both the inner and the outer pixels (that in MAGIC
179// have a different area) are compared to the same pedestal RMS, coming
180// from the inner pixels.
181//
182// Make sure that you used a class calculating the MPedPhotCam which also
183// updated the contents of the mean values (Recalc) correctly.
184//
185//
186// PROBABILITY CLEANING
187// ====================
188// This method takes signal height (over signal noise) and arrival time
189// into account. Instead of comparing signal/Noise with cleaning level
190// one and two, we calculate
191// - P_ped: The probability that a signal is a pedestal (using
192// the signal height and the pedestal) For this probability the
193// same algorithm like in kScaled is used (which is a standard
194// cleaning which scales the noise with the mean noise of pixels
195// with the same size)
196// - P_sig: The probability that the signal corresponds to the pixel
197// with the highest signal. For this probability we use the
198// arrival time only.
199//
200// The cleaning now is done in levels of Probability (eg. 0.2, 0.05)
201// The meaning of the cleaning levels is essentially the same (the same cleaning
202// algorithm is used) but the cleaning is not done in levels of signal/noise
203// but in level of this probability.
204//
205// This probability is calculated as (1-P_ped)*P_sig
206//
207// Example:
208//
209// MImgCleanStd clean(0.2, 0.05);
210// clean.SetMethod(MImgCleanStd::kProbability);
211//
212//
213// Member Function: SetMethod()
214// ============================
215// When you call the MImgCleanStd task, the default method is kStandard.
216//
217// If you want to switch to the kDemocratic method you have to
218// call this member function.
219//
220// Example:
221//
222// MImgCleanStd clean;
223// //creates a default Cleaning object, with default setting
224//
225// clean.SetMethod(MImgCleanStd::kDemocratic);
226// //now the method of cleaning is changed to Democratic
227//
228//
229// FIRST AND SECOND CLEANING LEVEL
230// ===============================
231// When you call the MImgCleanStd task, the default cleaning levels are
232// fCleanLvl1 = 3, fCleanLvl2 = 2.5. You can change them easily when you
233// create the MImgCleanStd object.
234//
235// Example:
236//
237// MImgCleanStd clean(Float_t lvl1,Float_t lvl2);
238// //creates a default cleaning object, but the cleaning levels are now
239// //lvl1 and lvl2.
240//
241// RING NUMBER
242// ===========
243// The standard cleaning procedure is such that it looks for the
244// informations of the boundary part of the shower only on the first
245// neighbors of the CORE pixels.
246// There is the possibility now to look not only at the firs neighbors
247// (first ring),but also further away, around the CORE pixels. All the new
248// pixels you can find with this method, are tested with the second level
249// of cleaning and have to have at least an USED neighbor.
250//
251// They will be also set as USED and will be taken into account during the
252// calculation of the image parameters.
253// The only way to distinguish them from the other USED pixels, is the
254// Ring number, that is bigger than 1.
255//
256// Example: You can decide how many rings you want to analyze using:
257//
258// MImgCleanStd clean;
259// //creates a default cleaning object (default number of rings =1)
260// clean.SetCleanRings(UShort_t r);
261// //now it looks r times around the CORE pixels to find new pixels with
262// //signal.
263//
264//
265// Input Containers:
266// MGeomCam
267// MPedPhotCam
268// MCerPhotEvt
269//
270// Output Containers:
271// MCerPhotEvt
272//
273/////////////////////////////////////////////////////////////////////////////
274#include "MImgCleanStd.h"
275
276#include <stdlib.h> // atof
277#include <fstream> // ofstream, SavePrimitive
278
279#include <TEnv.h>
280
281#include <TGFrame.h> // TGFrame
282#include <TGLabel.h> // TGLabel
283#include <TGTextEntry.h> // TGTextEntry
284
285#include "MLog.h"
286#include "MLogManip.h"
287
288#include "MParList.h"
289#include "MCameraData.h"
290
291#include "MGeomPix.h"
292#include "MGeomCam.h"
293
294#include "MCerPhotPix.h"
295#include "MCerPhotEvt.h"
296
297#include "MGGroupFrame.h" // MGGroupFrame
298
299ClassImp(MImgCleanStd);
300
301using namespace std;
302
303enum {
304 kImgCleanLvl1,
305 kImgCleanLvl2
306};
307
308static const TString gsDefName = "MImgCleanStd";
309static const TString gsDefTitle = "Task to perform image cleaning";
310
311const TString MImgCleanStd::gsNamePedPhotCam="MPedPhotCam"; // default name of the 'MPedPhotCam' container
312
313// --------------------------------------------------------------------------
314//
315// Default constructor. Here you can specify the cleaning method and levels.
316// If you don't specify them the 'common standard' values 3.0 and 2.5 (sigma
317// above mean) are used.
318// Here you can also specify how many rings around the core pixels you want
319// to analyze (with the fixed lvl2). The default value for "rings" is 1.
320//
321MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
322 const char *name, const char *title)
323 : fCleaningMethod(kStandard), fCleanLvl1(lvl1),
324 fCleanLvl2(lvl2), fCleanRings(1), fNamePedPhotCam(gsNamePedPhotCam)
325
326{
327 fName = name ? name : gsDefName.Data();
328 fTitle = title ? title : gsDefTitle.Data();
329
330 Print();
331}
332
333// --------------------------------------------------------------------------
334//
335// The first step of cleaning defines the CORE pixels. All the other pixels
336// are set as UNUSED and belong to RING 0.
337// After this point, only the CORE pixels are set as USED, with RING
338// number 1.
339//
340// NT 28/04/2003: now the option to use the standard method or the
341// democratic method is implemented:
342//
343// kStandard: This method looks for all pixels with an entry (photons)
344// that is three times bigger than the noise of the pixel
345// (default: 3 sigma, clean level 1)
346//
347// kDemocratic: this method looks for all pixels with an entry (photons)
348// that is n times bigger than the noise of the mean of the
349// inner pixels (default: 3 sigmabar, clean level 1)
350//
351//
352void MImgCleanStd::CleanStep1()
353{
354 const TArrayD &data = fData->GetData();
355
356 //
357 // check the number of all pixels against the noise level and
358 // set them to 'unused' state if necessary
359 //
360 MCerPhotPix *pix;
361
362 // Loop over all pixels
363 MCerPhotEvtIter Next(fEvt, kFALSE);
364 while ((pix=static_cast<MCerPhotPix*>(Next())))
365 if (!pix->IsPixelUnmapped() && data[pix->GetPixId()] <= fCleanLvl1)
366 pix->SetPixelUnused();
367}
368
369// --------------------------------------------------------------------------
370//
371// Check if the survived pixel have a neighbor, that also
372// survived, otherwise set pixel to unused (removes pixels without
373// neighbors).
374//
375void MImgCleanStd::CleanStep2()
376{
377 MCerPhotPix *pix;
378
379 // Loop over used pixels only
380 TIter Next(*fEvt);
381
382 while ((pix=static_cast<MCerPhotPix*>(Next())))
383 {
384 // get pixel id of this entry
385 const Int_t idx = pix->GetPixId();
386
387 // check for 'used' neighbors of this pixel
388 const MGeomPix &gpix = (*fCam)[idx];
389 const Int_t nnmax = gpix.GetNumNeighbors();
390
391 Bool_t hasNeighbor = kFALSE;
392
393 //loop on the neighbors to check if they are used
394 for (Int_t j=0; j<nnmax; j++)
395 {
396 const Int_t idx2 = gpix.GetNeighbor(j);
397
398 // when you find an used neighbor, break the loop
399 if (fEvt->IsPixelUsed(idx2))
400 {
401 hasNeighbor = kTRUE;
402 break;
403 }
404 }
405
406 if (hasNeighbor == kFALSE)
407 pix->SetPixelUnused();
408 }
409
410 //
411 // now we declare all pixels that survive as CorePixels
412 //
413
414 Next.Reset();
415 while ((pix=static_cast<MCerPhotPix*>(Next())))
416 {
417 if (pix->IsPixelUsed())
418 pix->SetPixelCore();
419 }
420}
421
422void MImgCleanStd::CleanStep3b(MCerPhotPix &pix)
423{
424 const Int_t idx = pix.GetPixId();
425
426 //
427 // check if the pixel's next neighbor is a core pixel.
428 // if it is a core pixel set pixel state to: used.
429 //
430 MGeomPix &gpix = (*fCam)[idx];
431 const Int_t nnmax = gpix.GetNumNeighbors();
432
433 for (Int_t j=0; j<nnmax; j++)
434 {
435 const Int_t idx2 = gpix.GetNeighbor(j);
436
437 if (!fEvt->IsPixelCore(idx2))
438 continue;
439
440 pix.SetPixelUsed();
441 break;
442 }
443}
444
445// --------------------------------------------------------------------------
446//
447// NT: Add option "rings": default value = 1.
448// Look n (n>1) times for the boundary pixels around the used pixels.
449// If a pixel has more than 2.5 (clean level 2.5) sigma,
450// it is declared as used.
451//
452// If a value<2 for fCleanRings is used, no CleanStep4 is done.
453//
454void MImgCleanStd::CleanStep4(UShort_t r, MCerPhotPix &pix)
455{
456 //
457 // Skip events that have already a defined status;
458 //
459 if (pix.GetRing() != 0)
460 return;
461
462 //
463 // check if the pixel's next neighbor is a used pixel.
464 // if it is a used pixel set pixel state to: used,
465 // and tell to which ring it belongs to.
466 //
467 const Int_t idx = pix.GetPixId();
468
469 MGeomPix &gpix = (*fCam)[idx];
470
471 const Int_t nnmax = gpix.GetNumNeighbors();
472
473 for (Int_t j=0; j<nnmax; j++)
474 {
475 const Int_t idx2 = gpix.GetNeighbor(j);
476
477 MCerPhotPix *npix = fEvt->GetPixById(idx2);
478 if (!npix || !npix->IsPixelUsed() || npix->GetRing()>r-1 )
479 continue;
480
481 pix.SetRing(r);
482 break;
483 }
484}
485
486// --------------------------------------------------------------------------
487//
488// Look for the boundary pixels around the core pixels
489// if a pixel has more than 2.5 (clean level 2.5) sigma, and
490// a core neigbor, it is declared as used.
491//
492void MImgCleanStd::CleanStep3()
493{
494 const TArrayD &data = fData->GetData();
495
496 for (UShort_t r=1; r<fCleanRings+1; r++)
497 {
498 MCerPhotPix *pix;
499
500 // Loop over all pixels
501
502 MCerPhotEvtIter NextAll(fEvt, kFALSE);
503 while ((pix=static_cast<MCerPhotPix*>(NextAll())))
504 {
505 //
506 // if pixel is a core pixel or unmapped, go to the next pixel
507 //
508 if (pix->IsPixelCore() || pix->IsPixelUnmapped())
509 continue;
510
511 if (data[pix->GetPixId()] <= fCleanLvl2)
512 continue;
513
514 if (r==1)
515 CleanStep3b(*pix);
516 else
517 CleanStep4(r, *pix);
518 }
519 }
520}
521
522// --------------------------------------------------------------------------
523//
524// Check if MEvtHeader exists in the Parameter list already.
525// if not create one and add them to the list
526//
527Int_t MImgCleanStd::PreProcess (MParList *pList)
528{
529 fCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
530 if (!fCam)
531 {
532 *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
533 return kFALSE;
534 }
535
536 fEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
537 if (!fEvt)
538 {
539 *fLog << err << "MCerPhotEvt not found... aborting." << endl;
540 return kFALSE;
541 }
542
543 fPed = (MPedPhotCam*)pList->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
544 if (!fPed)
545 {
546 *fLog << err << "MPedPhotCam not found... aborting." << endl;
547 return kFALSE;
548 }
549
550 fTime = (MArrivalTime*)pList->FindObject(AddSerialNumber("MArrivalTime"));
551 if (!fTime && fCleaningMethod==kProbability)
552 *fLog << warn << "MArrivalTime not found... probability cleaning done with signal only!" << endl;
553
554 fData = (MCameraData*)pList->FindCreateObj(AddSerialNumber("MCameraData"));
555 if (!fData)
556 return kFALSE;
557
558 return kTRUE;
559}
560
561// --------------------------------------------------------------------------
562//
563// Cleans the image.
564//
565Int_t MImgCleanStd::Process()
566{
567 switch (fCleaningMethod)
568 {
569 case kStandard:
570 fData->CalcCleaningLevel(*fEvt, *fPed, *fCam);
571 break;
572 case kScaled:
573 fData->CalcCleaningLevel2(*fEvt, *fPed, *fCam);
574 break;
575 case kDemocratic:
576 fData->CalcCleaningLevelDemocratic(*fEvt, *fPed, *fCam);
577 break;
578 case kProbability:
579 fData->CalcCleaningProbability(*fEvt, *fPed, *fCam, fTime);
580 break;
581 default:
582 break;
583 }
584
585#ifdef DEBUG
586 *fLog << all << "CleanStep 1" << endl;
587#endif
588 CleanStep1();
589
590
591#ifdef DEBUG
592 *fLog << all << "CleanStep 2" << endl;
593#endif
594 CleanStep2();
595
596 // For speed reasons skip the rest of the cleaning if no
597 // action will be taken!
598 if (fCleanLvl1>fCleanLvl2)
599 {
600#ifdef DEBUG
601 *fLog << all << "CleanStep 3" << endl;
602#endif
603 CleanStep3();
604 }
605
606#ifdef DEBUG
607 *fLog << all << "Calc Islands" << endl;
608#endif
609 // Takes roughly 10% of the time
610 fEvt->CalcIslands(*fCam);
611
612#ifdef DEBUG
613 *fLog << all << "Done." << endl;
614#endif
615
616 return kTRUE;
617}
618
619// --------------------------------------------------------------------------
620//
621// Print descriptor and cleaning levels.
622//
623void MImgCleanStd::Print(Option_t *o) const
624{
625 *fLog << all << GetDescriptor() << " using ";
626 switch (fCleaningMethod)
627 {
628 case kDemocratic:
629 *fLog << "democratic";
630 break;
631 case kStandard:
632 *fLog << "standard";
633 break;
634 case kScaled:
635 *fLog << "scaled";
636 break;
637 case kProbability:
638 *fLog << "probability";
639 break;
640 }
641 *fLog << " cleaning initialized with noise level " << fCleanLvl1 << " and " << fCleanLvl2;
642 *fLog << " (CleanRings=" << fCleanRings << ")" << endl;
643}
644
645// --------------------------------------------------------------------------
646//
647// Create two text entry fields, one for each cleaning level and a
648// describing text line.
649//
650void MImgCleanStd::CreateGuiElements(MGGroupFrame *f)
651{
652 //
653 // Create a frame for line 3 and 4 to be able
654 // to align entry field and label in one line
655 //
656 TGHorizontalFrame *f1 = new TGHorizontalFrame(f, 0, 0);
657 TGHorizontalFrame *f2 = new TGHorizontalFrame(f, 0, 0);
658
659 /*
660 * --> use with root >=3.02 <--
661 *
662
663 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
664 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
665
666 */
667 TGTextEntry *entry1 = new TGTextEntry(f1, "****", kImgCleanLvl1);
668 TGTextEntry *entry2 = new TGTextEntry(f2, "****", kImgCleanLvl2);
669
670 // --- doesn't work like expected (until root 3.02?) --- fNumEntry1->SetAlignment(kTextRight);
671 // --- doesn't work like expected (until root 3.02?) --- fNumEntry2->SetAlignment(kTextRight);
672
673 entry1->SetText("3.0");
674 entry2->SetText("2.5");
675
676 entry1->Associate(f);
677 entry2->Associate(f);
678
679 TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1");
680 TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2");
681
682 l1->SetTextJustify(kTextLeft);
683 l2->SetTextJustify(kTextLeft);
684
685 //
686 // Align the text of the label centered, left in the row
687 // with a left padding of 10
688 //
689 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10);
690 TGLayoutHints *layframe = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 5, 0, 10);
691
692 //
693 // Add one entry field and the corresponding label to each line
694 //
695 f1->AddFrame(entry1);
696 f2->AddFrame(entry2);
697
698 f1->AddFrame(l1, laylabel);
699 f2->AddFrame(l2, laylabel);
700
701 f->AddFrame(f1, layframe);
702 f->AddFrame(f2, layframe);
703
704 f->AddToList(entry1);
705 f->AddToList(entry2);
706 f->AddToList(l1);
707 f->AddToList(l2);
708 f->AddToList(laylabel);
709 f->AddToList(layframe);
710}
711
712// --------------------------------------------------------------------------
713//
714// Process the GUI Events comming from the two text entry fields.
715//
716Bool_t MImgCleanStd::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
717{
718 if (msg!=kC_TEXTENTRY || submsg!=kTE_ENTER)
719 return kTRUE;
720
721 TGTextEntry *txt = (TGTextEntry*)FindWidget(param1);
722
723 if (!txt)
724 return kTRUE;
725
726 Float_t lvl = atof(txt->GetText());
727
728 switch (param1)
729 {
730 case kImgCleanLvl1:
731 fCleanLvl1 = lvl;
732 *fLog << "Cleaning level 1 set to " << lvl << " sigma." << endl;
733 return kTRUE;
734
735 case kImgCleanLvl2:
736 fCleanLvl2 = lvl;
737 *fLog << "Cleaning level 2 set to " << lvl << " sigma." << endl;
738 return kTRUE;
739 }
740
741 return kTRUE;
742}
743
744// --------------------------------------------------------------------------
745//
746// Implementation of SavePrimitive. Used to write the call to a constructor
747// to a macro. In the original root implementation it is used to write
748// gui elements to a macro-file.
749//
750void MImgCleanStd::StreamPrimitive(ofstream &out) const
751{
752 out << " MImgCleanStd " << GetUniqueName() << "(";
753 out << fCleanLvl1 << ", " << fCleanLvl2;
754
755 if (fName!=gsDefName || fTitle!=gsDefTitle)
756 {
757 out << ", \"" << fName << "\"";
758 if (fTitle!=gsDefTitle)
759 out << ", \"" << fTitle << "\"";
760 }
761 out << ");" << endl;
762
763 if (fCleaningMethod!=kStandard)
764 {
765 out << " " << GetUniqueName() << ".SetMethod(MImgCleanStd::k";
766 switch (fCleaningMethod)
767 {
768 case kScaled: out << "Scaled"; break;
769 case kDemocratic: out << "Democratic"; break;
770 case kProbability: out << "Probability"; break;
771 default:
772 break;
773 }
774 out << ");" << endl;
775 }
776 if (fCleanRings!=1)
777 out << " " << GetUniqueName() << ".SetCleanRings(" << fCleanRings << ");" << endl;
778
779 if (gsNamePedPhotCam!=fNamePedPhotCam)
780 out << " " << GetUniqueName() << ".SetNamePedPhotCam(\"" << fNamePedPhotCam << "\");" << endl;
781}
782
783// --------------------------------------------------------------------------
784//
785// Read the setup from a TEnv, eg:
786// MImgCleanStd.CleanLevel1: 3.0
787// MImgCleanStd.CleanLevel2: 2.5
788// MImgCleanStd.CleanMethod: Standard, Scaled, Democratic, Probability
789// MImgCleanStd.CleanRings: 1
790//
791Int_t MImgCleanStd::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
792{
793 Bool_t rc = kFALSE;
794 if (IsEnvDefined(env, prefix, "CleanRings", print))
795 {
796 rc = kTRUE;
797 SetCleanRings(GetEnvValue(env, prefix, "CleanRings", fCleanRings));
798 }
799 if (IsEnvDefined(env, prefix, "CleanLevel1", print))
800 {
801 rc = kTRUE;
802 fCleanLvl1 = GetEnvValue(env, prefix, "CleanLevel1", fCleanLvl1);
803 }
804 if (IsEnvDefined(env, prefix, "CleanLevel2", print))
805 {
806 rc = kTRUE;
807 fCleanLvl2 = GetEnvValue(env, prefix, "CleanLevel2", fCleanLvl2);
808 }
809
810 if (IsEnvDefined(env, prefix, "CleanMethod", print))
811 {
812 rc = kTRUE;
813 TString s = GetEnvValue(env, prefix, "CleanMethod", "");
814 s.ToLower();
815 if (s.BeginsWith("standard"))
816 SetMethod(kStandard);
817 if (s.BeginsWith("scaled"))
818 SetMethod(kScaled);
819 if (s.BeginsWith("democratic"))
820 SetMethod(kDemocratic);
821 if (s.BeginsWith("probability"))
822 SetMethod(kProbability);
823 }
824
825 return rc;
826}
Note: See TracBrowser for help on using the repository browser.