Skip to content

Commit

Permalink
Merge pull request #526 from rest-for-physics/jgalan_radial_good
Browse files Browse the repository at this point in the history
Creating new TRestRadialStrippedMask
  • Loading branch information
jgalan authored Jun 16, 2024
2 parents 9591b5a + 3591991 commit 5772e6b
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 13 deletions.
Binary file added doc/doxygen/images/radialstrippedmask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/masks.rml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
<parameter name="stripsGap" value="12mm"/>
<parameter name="stripsThickness" value="1.2mm"/>
</TRestStrippedMask>
<TRestRadialStrippedMask name="radialStrips" verboseLevel="warning">
<parameter name="maskRadius" value="19.4cm" />
<parameter name="offset" value="(0,0)cm" />
<parameter name="rotationAngle" value="30degrees" />

<parameter name="initialRadius" value="5.4cm" />
<parameter name="internalRegionRadius" value="0cm" />

<parameter name="stripsAngle" value="60degrees" />
<parameter name="stripsThickness" value="0.7cm" />
</TRestRadialStrippedMask>
<TRestRingsMask name="rings" verboseLevel="warning">
<parameter name="maskRadius" value="9cm"/>
<parameter name="offset" value="(3,3)mm"/>
Expand Down
2 changes: 1 addition & 1 deletion source/framework/masks/inc/TRestPatternMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// An abstract class used to encapsulate different mask pattern class definitions.
class TRestPatternMask : public TRestMetadata {
private:
/// It is used to introduce an offset on the pattern
/// It is used to introduce an offset on the pattern (not the mask, mask is always centered)
TVector2 fOffset = TVector2(0, 0); //<

/// An angle (in radians) used to introduce a rotation to the pattern
Expand Down
70 changes: 70 additions & 0 deletions source/framework/masks/inc/TRestRadialStrippedMask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*************************************************************************
* This file is part of the REST software framework. *
* *
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
* For more information see https://gifna.unizar.es/trex *
* *
* REST is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* REST is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have a copy of the GNU General Public License along with *
* REST in $REST_PATH/LICENSE. *
* If not, see https://www.gnu.org/licenses/. *
* For the list of contributors see $REST_PATH/CREDITS. *
*************************************************************************/

#ifndef REST_TRestRadialStrippedMask
#define REST_TRestRadialStrippedMask

#include <TRestPatternMask.h>

/// A class used to define a stripped mask pattern
class TRestRadialStrippedMask : public TRestPatternMask {
private:
void Initialize() override;

/// The periodity of the stripped structure in radians
Double_t fStripsAngle = TMath::Pi() / 3; //<

/// The width of the stripped structure in mm
Double_t fStripsThickness = 0.5; //<

/// The spacers structure will be effective from this radius, in mm. Default is from 20 mm.
Double_t fInitialRadius = 20.; //<

/// Radius of an internal circular region defined inside the fInitialRadius. If 0, there will be no region
Double_t fInternalRegionRadius = 0.; //<

/// It defines the maximum number of cells/regions in each axis
Int_t fModulus = 10;

public:
virtual Int_t GetRegion(Double_t& x, Double_t& y) override;

/// It returns the gap/periodicity of the strips in degrees
Double_t GetStripsAngle() { return fStripsAngle * units("degrees"); }

/// It returns the thickness of the strips in mm
Double_t GetStripsThickness() { return fStripsThickness; }

/// It returns the modulus used to define a finite set of ids
Int_t GetModulus() { return fModulus; }

void PrintMetadata() override;
void PrintMaskMembers() override;
void PrintMask() override;

TRestRadialStrippedMask();
TRestRadialStrippedMask(const char* cfgFileName, std::string name = "");
~TRestRadialStrippedMask();

ClassDefOverride(TRestRadialStrippedMask, 1);
};
#endif
12 changes: 7 additions & 5 deletions source/framework/masks/src/TRestPatternMask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ TCanvas* TRestPatternMask::DrawMonteCarlo(Int_t nSamples) {
delete fCanvas;
fCanvas = NULL;
}
fCanvas = new TCanvas("canv", "This is the canvas title", 1400, 1200);
fCanvas = new TCanvas("canv", "This is the canvas title", 1200, 1200);
fCanvas->Draw();

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

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

Int_t id = GetRegion(x, y);

if (points.count(id) == 0) {
std::vector<TVector2> a;
a.push_back(TVector2(x, y));
a.push_back(TVector2(xO, yO));
points[id] = a;
} else {
points[id].push_back(TVector2(x, y));
points[id].push_back(TVector2(xO, yO));
}
}

Expand Down
221 changes: 221 additions & 0 deletions source/framework/masks/src/TRestRadialStrippedMask.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*************************************************************************
* This file is part of the REST software framework. *
* *
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
* For more information see https://gifna.unizar.es/trex *
* *
* REST is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* REST is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have a copy of the GNU General Public License along with *
* REST in $REST_PATH/LICENSE. *
* If not, see https://www.gnu.org/licenses/. *
* For the list of contributors see $REST_PATH/CREDITS. *
*************************************************************************/

/////////////////////////////////////////////////////////////////////////
/// This class defines a stripped pattern. It defines a periodicity
/// and a thickness for the strips. The method TRestRadialStrippedMask::GetRegion
/// will return a unique id for each region in between strips.
///
/// The stripped structure is centered in (0,0) and it can be shifted using
/// the offset defined inside TRestPatternMask. The pattern will be only
/// delimited by the limits imposed inside TRestPatternMask.
///
/// ### Specific stripped metadata parameters
///
/// * **stripsAngle**: This parameter defines the strips angular periodicity.
/// * **stripsThickness**: The thickness of the strips.
/// * **modulus**: A number that defines the range of ids used to identify
/// the different regions inside the stripped pattern. If modulus is 10,
/// then we will only be able to identify up to 10 unique regions. If a
/// larger amount of regions is found, it will happen that two regions will
/// be assigned the same id.
///
/// ### Common pattern metadata parameters
///
/// On top of the metadata class parameters, we may define common pattern
/// parameters to induce an offset and rotation to the pattern.
///
/// * **offset**: A parameter to shift the pattern window mask.
/// * **rotationAngle**: An angle given in radians to rotate the pattern.
/// * **maskRadius**: A radius defining the limits of the circular mask.
///
/// ### Examples
///
/// Mask pattern RML definitions can be found inside the file
/// `REST_PATH/examples/masks.rml`.
///
/// The following definition ilustrates a complete RML implementation of a
/// TRestRadialStrippedMask.
///
/// \code
/// <TRestRadialStrippedMask name="strongback" verboseLevel="warning">
/// <parameter name="maskRadius" value="30cm" />
/// <parameter name="offset" value="(5,5)cm" />
/// <parameter name="rotationAngle" value="30degrees" />
///
/// <parameter name="stripsAngle" value="60degrees" />
/// <parameter name="stripsThickness" value="2.5cm" />
/// </TRestRadialStrippedMask>
/// \endcode
///
/// The basic use of this class is provided by the TRestRadialStrippedMask::GetRegion
/// method. For example:
///
/// \code
/// TRestRadialStrippedMask mask("masks.rml", "radialStrips");
/// Int_t id = mask.GetRegion( 12.5, 4.3 );
/// std::cout << "Region id is : " << id << endl;
/// \endcode
///
/// The following figure may be generated using the TRestPatternMask::DrawMonteCarlo
/// method.
///
/// \code
/// TRestRadialStrippedMask mask("masks.rml", "radialStrips");
/// TCanvas *c = mask.DrawMonteCarlo(30000);
/// c->Draw();
/// c->Print("radialstrippedmask.png");
/// \endcode
///
/// \htmlonly <style>div.image img[src="radialstrippedmask.png"]{width:500px;}</style> \endhtmlonly
/// ![An illustration of the montecarlo mask test using DrawMonteCarlo](strippedmask.png)
///
///----------------------------------------------------------------------
///
/// REST-for-Physics - Software for Rare Event Searches Toolkit
///
/// History of developments:
///
/// 2022-05: First implementation of TRestRadialStrippedMask
/// Javier Galan
///
/// \class TRestRadialStrippedMask
/// \author: Javier Galan - javier.galan@unizar.es
///
/// <hr>
///

#include "TRestRadialStrippedMask.h"

#include "TRandom3.h"

ClassImp(TRestRadialStrippedMask);

///////////////////////////////////////////////
/// \brief Default constructor
///
TRestRadialStrippedMask::TRestRadialStrippedMask() : TRestPatternMask() { Initialize(); }

/////////////////////////////////////////////
/// \brief Constructor loading data from a config file
///
/// If no configuration path is defined using TRestMetadata::SetConfigFilePath
/// the path to the config file must be specified using full path, absolute or
/// relative.
///
/// The default behaviour is that the config file must be specified with
/// full path, absolute or relative.
///
/// \param cfgFileName A const char* giving the path to an RML file.
/// \param name The name of the specific metadata. It will be used to find the
/// corresponding TRestRadialStrippedMask section inside the RML.
///
TRestRadialStrippedMask::TRestRadialStrippedMask(const char* cfgFileName, std::string name)
: TRestPatternMask(cfgFileName) {
Initialize();

LoadConfigFromFile(fConfigFileName, name);

if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) PrintMetadata();
}

///////////////////////////////////////////////
/// \brief Default destructor
///
TRestRadialStrippedMask::~TRestRadialStrippedMask() {}

///////////////////////////////////////////////
/// \brief Function to initialize input/output event members and define
/// the section name
///
void TRestRadialStrippedMask::Initialize() {
SetSectionName(this->ClassName());
SetType("RadialStripped");
}

///////////////////////////////////////////////
/// \brief It returns a number identifying the region where the particle
/// with coordinates (x,y) felt in. The method returns 0 if the particle
/// hits the pattern.
///
/// The particle will be counter-rotated to emulate the mask rotation
/// using the method TRestPatternMask::ApplyCommonMaskTransformation
///
Int_t TRestRadialStrippedMask::GetRegion(Double_t& x, Double_t& y) {
if (TRestPatternMask::GetRegion(x, y)) return 0;

Double_t d = TMath::Sqrt(x * x + y * y);

if (d < fInitialRadius) {
if (fInternalRegionRadius > 0 && d < fInternalRegionRadius) return 1;

return 0;
}

TVector2 point(x, y);
Double_t phi = point.Phi();

/// phi determines the region where the point is found
Int_t region = (Int_t)(phi / fStripsAngle);
region = 2 + region % fMaxRegions;

Double_t angle = 0;
/// Checking if we hit an arm
while (angle < 2 * TMath::Pi()) {
if (point.Y() < fStripsThickness / 2. && point.Y() > -fStripsThickness / 2. && point.X() >= 0)
return 0;

point = point.Rotate(fStripsAngle);
angle += fStripsAngle;
}

return 1 + region % fModulus;
}

/////////////////////////////////////////////
/// \brief Prints on screen the complete information about the metadata members from this class
///
void TRestRadialStrippedMask::PrintMetadata() {
TRestPatternMask::PrintMetadata();

PrintMaskMembers();
RESTMetadata << "++++" << RESTendl;
}

/////////////////////////////////////////////
/// \brief Prints on screen the information about the metadata members of TRestRingsMask,
/// including common pattern headers, but without common metadata headers.
///
void TRestRadialStrippedMask::PrintMask() {
PrintCommonPatternMembers();
RESTMetadata << "----" << RESTendl;
PrintMaskMembers();
}

/////////////////////////////////////////////
/// \brief Prints on screen the information about the metadata members of TRestRingsMask,
/// excluding common metadata headers.
///
void TRestRadialStrippedMask::PrintMaskMembers() {
RESTMetadata << " - Strips angle : " << fStripsAngle * units("degrees") << " degrees" << RESTendl;
RESTMetadata << " - Strips thickness : " << fStripsThickness << " mm" << RESTendl;
}
6 changes: 3 additions & 3 deletions source/framework/sensitivity/inc/TRestSensitivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TRestSensitivity : public TRestMetadata {
Bool_t fFrozen = false; //< Only needed if we add experiments by other means than RML

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

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

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

TH1D* SignalStatisticalTest(Double_t node, Int_t N);

Expand Down
Loading

0 comments on commit 5772e6b

Please sign in to comment.