Skip to content

Commit 5772e6b

Browse files
authored
Merge pull request #526 from rest-for-physics/jgalan_radial_good
Creating new TRestRadialStrippedMask
2 parents 9591b5a + 3591991 commit 5772e6b

File tree

8 files changed

+317
-13
lines changed

8 files changed

+317
-13
lines changed
1.79 MB
Loading

examples/masks.rml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
<parameter name="stripsGap" value="12mm"/>
1515
<parameter name="stripsThickness" value="1.2mm"/>
1616
</TRestStrippedMask>
17+
<TRestRadialStrippedMask name="radialStrips" verboseLevel="warning">
18+
<parameter name="maskRadius" value="19.4cm" />
19+
<parameter name="offset" value="(0,0)cm" />
20+
<parameter name="rotationAngle" value="30degrees" />
21+
22+
<parameter name="initialRadius" value="5.4cm" />
23+
<parameter name="internalRegionRadius" value="0cm" />
24+
25+
<parameter name="stripsAngle" value="60degrees" />
26+
<parameter name="stripsThickness" value="0.7cm" />
27+
</TRestRadialStrippedMask>
1728
<TRestRingsMask name="rings" verboseLevel="warning">
1829
<parameter name="maskRadius" value="9cm"/>
1930
<parameter name="offset" value="(3,3)mm"/>

source/framework/masks/inc/TRestPatternMask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// An abstract class used to encapsulate different mask pattern class definitions.
3030
class TRestPatternMask : public TRestMetadata {
3131
private:
32-
/// It is used to introduce an offset on the pattern
32+
/// It is used to introduce an offset on the pattern (not the mask, mask is always centered)
3333
TVector2 fOffset = TVector2(0, 0); //<
3434

3535
/// An angle (in radians) used to introduce a rotation to the pattern
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*************************************************************************
2+
* This file is part of the REST software framework. *
3+
* *
4+
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5+
* For more information see https://gifna.unizar.es/trex *
6+
* *
7+
* REST is free software: you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation, either version 3 of the License, or *
10+
* (at your option) any later version. *
11+
* *
12+
* REST is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15+
* GNU General Public License for more details. *
16+
* *
17+
* You should have a copy of the GNU General Public License along with *
18+
* REST in $REST_PATH/LICENSE. *
19+
* If not, see https://www.gnu.org/licenses/. *
20+
* For the list of contributors see $REST_PATH/CREDITS. *
21+
*************************************************************************/
22+
23+
#ifndef REST_TRestRadialStrippedMask
24+
#define REST_TRestRadialStrippedMask
25+
26+
#include <TRestPatternMask.h>
27+
28+
/// A class used to define a stripped mask pattern
29+
class TRestRadialStrippedMask : public TRestPatternMask {
30+
private:
31+
void Initialize() override;
32+
33+
/// The periodity of the stripped structure in radians
34+
Double_t fStripsAngle = TMath::Pi() / 3; //<
35+
36+
/// The width of the stripped structure in mm
37+
Double_t fStripsThickness = 0.5; //<
38+
39+
/// The spacers structure will be effective from this radius, in mm. Default is from 20 mm.
40+
Double_t fInitialRadius = 20.; //<
41+
42+
/// Radius of an internal circular region defined inside the fInitialRadius. If 0, there will be no region
43+
Double_t fInternalRegionRadius = 0.; //<
44+
45+
/// It defines the maximum number of cells/regions in each axis
46+
Int_t fModulus = 10;
47+
48+
public:
49+
virtual Int_t GetRegion(Double_t& x, Double_t& y) override;
50+
51+
/// It returns the gap/periodicity of the strips in degrees
52+
Double_t GetStripsAngle() { return fStripsAngle * units("degrees"); }
53+
54+
/// It returns the thickness of the strips in mm
55+
Double_t GetStripsThickness() { return fStripsThickness; }
56+
57+
/// It returns the modulus used to define a finite set of ids
58+
Int_t GetModulus() { return fModulus; }
59+
60+
void PrintMetadata() override;
61+
void PrintMaskMembers() override;
62+
void PrintMask() override;
63+
64+
TRestRadialStrippedMask();
65+
TRestRadialStrippedMask(const char* cfgFileName, std::string name = "");
66+
~TRestRadialStrippedMask();
67+
68+
ClassDefOverride(TRestRadialStrippedMask, 1);
69+
};
70+
#endif

source/framework/masks/src/TRestPatternMask.cxx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ TCanvas* TRestPatternMask::DrawMonteCarlo(Int_t nSamples) {
167167
delete fCanvas;
168168
fCanvas = NULL;
169169
}
170-
fCanvas = new TCanvas("canv", "This is the canvas title", 1400, 1200);
170+
fCanvas = new TCanvas("canv", "This is the canvas title", 1200, 1200);
171171
fCanvas->Draw();
172172

173173
TPad* pad1 = new TPad("pad1", "This is pad1", 0.01, 0.02, 0.99, 0.97);
@@ -183,17 +183,19 @@ TCanvas* TRestPatternMask::DrawMonteCarlo(Int_t nSamples) {
183183
TRandom3* rnd = new TRandom3(0);
184184

185185
for (int n = 0; n < nSamples; n++) {
186-
Double_t x = 2.5 * (rnd->Rndm() - 0.5) * fMaskRadius;
187-
Double_t y = 2.5 * (rnd->Rndm() - 0.5) * fMaskRadius;
186+
Double_t xO = 2.5 * (rnd->Rndm() - 0.5) * fMaskRadius;
187+
Double_t yO = 2.5 * (rnd->Rndm() - 0.5) * fMaskRadius;
188+
Double_t x = xO;
189+
Double_t y = yO;
188190

189191
Int_t id = GetRegion(x, y);
190192

191193
if (points.count(id) == 0) {
192194
std::vector<TVector2> a;
193-
a.push_back(TVector2(x, y));
195+
a.push_back(TVector2(xO, yO));
194196
points[id] = a;
195197
} else {
196-
points[id].push_back(TVector2(x, y));
198+
points[id].push_back(TVector2(xO, yO));
197199
}
198200
}
199201

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/*************************************************************************
2+
* This file is part of the REST software framework. *
3+
* *
4+
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5+
* For more information see https://gifna.unizar.es/trex *
6+
* *
7+
* REST is free software: you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation, either version 3 of the License, or *
10+
* (at your option) any later version. *
11+
* *
12+
* REST is distributed in the hope that it will be useful, *
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15+
* GNU General Public License for more details. *
16+
* *
17+
* You should have a copy of the GNU General Public License along with *
18+
* REST in $REST_PATH/LICENSE. *
19+
* If not, see https://www.gnu.org/licenses/. *
20+
* For the list of contributors see $REST_PATH/CREDITS. *
21+
*************************************************************************/
22+
23+
/////////////////////////////////////////////////////////////////////////
24+
/// This class defines a stripped pattern. It defines a periodicity
25+
/// and a thickness for the strips. The method TRestRadialStrippedMask::GetRegion
26+
/// will return a unique id for each region in between strips.
27+
///
28+
/// The stripped structure is centered in (0,0) and it can be shifted using
29+
/// the offset defined inside TRestPatternMask. The pattern will be only
30+
/// delimited by the limits imposed inside TRestPatternMask.
31+
///
32+
/// ### Specific stripped metadata parameters
33+
///
34+
/// * **stripsAngle**: This parameter defines the strips angular periodicity.
35+
/// * **stripsThickness**: The thickness of the strips.
36+
/// * **modulus**: A number that defines the range of ids used to identify
37+
/// the different regions inside the stripped pattern. If modulus is 10,
38+
/// then we will only be able to identify up to 10 unique regions. If a
39+
/// larger amount of regions is found, it will happen that two regions will
40+
/// be assigned the same id.
41+
///
42+
/// ### Common pattern metadata parameters
43+
///
44+
/// On top of the metadata class parameters, we may define common pattern
45+
/// parameters to induce an offset and rotation to the pattern.
46+
///
47+
/// * **offset**: A parameter to shift the pattern window mask.
48+
/// * **rotationAngle**: An angle given in radians to rotate the pattern.
49+
/// * **maskRadius**: A radius defining the limits of the circular mask.
50+
///
51+
/// ### Examples
52+
///
53+
/// Mask pattern RML definitions can be found inside the file
54+
/// `REST_PATH/examples/masks.rml`.
55+
///
56+
/// The following definition ilustrates a complete RML implementation of a
57+
/// TRestRadialStrippedMask.
58+
///
59+
/// \code
60+
/// <TRestRadialStrippedMask name="strongback" verboseLevel="warning">
61+
/// <parameter name="maskRadius" value="30cm" />
62+
/// <parameter name="offset" value="(5,5)cm" />
63+
/// <parameter name="rotationAngle" value="30degrees" />
64+
///
65+
/// <parameter name="stripsAngle" value="60degrees" />
66+
/// <parameter name="stripsThickness" value="2.5cm" />
67+
/// </TRestRadialStrippedMask>
68+
/// \endcode
69+
///
70+
/// The basic use of this class is provided by the TRestRadialStrippedMask::GetRegion
71+
/// method. For example:
72+
///
73+
/// \code
74+
/// TRestRadialStrippedMask mask("masks.rml", "radialStrips");
75+
/// Int_t id = mask.GetRegion( 12.5, 4.3 );
76+
/// std::cout << "Region id is : " << id << endl;
77+
/// \endcode
78+
///
79+
/// The following figure may be generated using the TRestPatternMask::DrawMonteCarlo
80+
/// method.
81+
///
82+
/// \code
83+
/// TRestRadialStrippedMask mask("masks.rml", "radialStrips");
84+
/// TCanvas *c = mask.DrawMonteCarlo(30000);
85+
/// c->Draw();
86+
/// c->Print("radialstrippedmask.png");
87+
/// \endcode
88+
///
89+
/// \htmlonly <style>div.image img[src="radialstrippedmask.png"]{width:500px;}</style> \endhtmlonly
90+
/// ![An illustration of the montecarlo mask test using DrawMonteCarlo](strippedmask.png)
91+
///
92+
///----------------------------------------------------------------------
93+
///
94+
/// REST-for-Physics - Software for Rare Event Searches Toolkit
95+
///
96+
/// History of developments:
97+
///
98+
/// 2022-05: First implementation of TRestRadialStrippedMask
99+
/// Javier Galan
100+
///
101+
/// \class TRestRadialStrippedMask
102+
/// \author: Javier Galan - [email protected]
103+
///
104+
/// <hr>
105+
///
106+
107+
#include "TRestRadialStrippedMask.h"
108+
109+
#include "TRandom3.h"
110+
111+
ClassImp(TRestRadialStrippedMask);
112+
113+
///////////////////////////////////////////////
114+
/// \brief Default constructor
115+
///
116+
TRestRadialStrippedMask::TRestRadialStrippedMask() : TRestPatternMask() { Initialize(); }
117+
118+
/////////////////////////////////////////////
119+
/// \brief Constructor loading data from a config file
120+
///
121+
/// If no configuration path is defined using TRestMetadata::SetConfigFilePath
122+
/// the path to the config file must be specified using full path, absolute or
123+
/// relative.
124+
///
125+
/// The default behaviour is that the config file must be specified with
126+
/// full path, absolute or relative.
127+
///
128+
/// \param cfgFileName A const char* giving the path to an RML file.
129+
/// \param name The name of the specific metadata. It will be used to find the
130+
/// corresponding TRestRadialStrippedMask section inside the RML.
131+
///
132+
TRestRadialStrippedMask::TRestRadialStrippedMask(const char* cfgFileName, std::string name)
133+
: TRestPatternMask(cfgFileName) {
134+
Initialize();
135+
136+
LoadConfigFromFile(fConfigFileName, name);
137+
138+
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata();
139+
}
140+
141+
///////////////////////////////////////////////
142+
/// \brief Default destructor
143+
///
144+
TRestRadialStrippedMask::~TRestRadialStrippedMask() {}
145+
146+
///////////////////////////////////////////////
147+
/// \brief Function to initialize input/output event members and define
148+
/// the section name
149+
///
150+
void TRestRadialStrippedMask::Initialize() {
151+
SetSectionName(this->ClassName());
152+
SetType("RadialStripped");
153+
}
154+
155+
///////////////////////////////////////////////
156+
/// \brief It returns a number identifying the region where the particle
157+
/// with coordinates (x,y) felt in. The method returns 0 if the particle
158+
/// hits the pattern.
159+
///
160+
/// The particle will be counter-rotated to emulate the mask rotation
161+
/// using the method TRestPatternMask::ApplyCommonMaskTransformation
162+
///
163+
Int_t TRestRadialStrippedMask::GetRegion(Double_t& x, Double_t& y) {
164+
if (TRestPatternMask::GetRegion(x, y)) return 0;
165+
166+
Double_t d = TMath::Sqrt(x * x + y * y);
167+
168+
if (d < fInitialRadius) {
169+
if (fInternalRegionRadius > 0 && d < fInternalRegionRadius) return 1;
170+
171+
return 0;
172+
}
173+
174+
TVector2 point(x, y);
175+
Double_t phi = point.Phi();
176+
177+
/// phi determines the region where the point is found
178+
Int_t region = (Int_t)(phi / fStripsAngle);
179+
region = 2 + region % fMaxRegions;
180+
181+
Double_t angle = 0;
182+
/// Checking if we hit an arm
183+
while (angle < 2 * TMath::Pi()) {
184+
if (point.Y() < fStripsThickness / 2. && point.Y() > -fStripsThickness / 2. && point.X() >= 0)
185+
return 0;
186+
187+
point = point.Rotate(fStripsAngle);
188+
angle += fStripsAngle;
189+
}
190+
191+
return 1 + region % fModulus;
192+
}
193+
194+
/////////////////////////////////////////////
195+
/// \brief Prints on screen the complete information about the metadata members from this class
196+
///
197+
void TRestRadialStrippedMask::PrintMetadata() {
198+
TRestPatternMask::PrintMetadata();
199+
200+
PrintMaskMembers();
201+
RESTMetadata << "++++" << RESTendl;
202+
}
203+
204+
/////////////////////////////////////////////
205+
/// \brief Prints on screen the information about the metadata members of TRestRingsMask,
206+
/// including common pattern headers, but without common metadata headers.
207+
///
208+
void TRestRadialStrippedMask::PrintMask() {
209+
PrintCommonPatternMembers();
210+
RESTMetadata << "----" << RESTendl;
211+
PrintMaskMembers();
212+
}
213+
214+
/////////////////////////////////////////////
215+
/// \brief Prints on screen the information about the metadata members of TRestRingsMask,
216+
/// excluding common metadata headers.
217+
///
218+
void TRestRadialStrippedMask::PrintMaskMembers() {
219+
RESTMetadata << " - Strips angle : " << fStripsAngle * units("degrees") << " degrees" << RESTendl;
220+
RESTMetadata << " - Strips thickness : " << fStripsThickness << " mm" << RESTendl;
221+
}

source/framework/sensitivity/inc/TRestSensitivity.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TRestSensitivity : public TRestMetadata {
4141
Bool_t fFrozen = false; //< Only needed if we add experiments by other means than RML
4242

4343
/// It is used to generate a histogram with the signal distribution produced with different signal samples
44-
TH1D* fSignalTest = nullptr;
44+
TH1D* fSignalTest = nullptr; //<
4545

4646
/// A canvas to draw
4747
TCanvas* fCanvas = nullptr; //!
@@ -69,8 +69,8 @@ class TRestSensitivity : public TRestMetadata {
6969
std::vector<Double_t> GetAveragedCurve();
7070
std::vector<std::vector<Double_t>> GetLevelCurves(const std::vector<Double_t>& levels);
7171

72-
void ExportCurve(std::string fname, int n);
73-
void ExportAveragedCurve(std::string fname);
72+
void ExportCurve(std::string fname, Double_t factor = 1.e-10, Double_t power = 0.25, int n = 0);
73+
void ExportAveragedCurve(std::string fname, Double_t factor = 1.e-10, Double_t power = 0.25);
7474

7575
TH1D* SignalStatisticalTest(Double_t node, Int_t N);
7676

0 commit comments

Comments
 (0)