REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestSpiderMask.cxx
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
115
116#include "TRestSpiderMask.h"
117
118#include "TRandom3.h"
119
120ClassImp(TRestSpiderMask);
121
126
141TRestSpiderMask::TRestSpiderMask(const char* cfgFileName, std::string name) : TRestPatternMask(cfgFileName) {
142 Initialize();
143
145
147}
148
153
159 SetSectionName(this->ClassName());
160 SetType("Spider");
161
163}
164
173Int_t TRestSpiderMask::GetRegion(Double_t& x, Double_t& y) {
174 if (TRestPatternMask::GetRegion(x, y)) return 0;
175
176 Double_t d = TMath::Sqrt(x * x + y * y);
177
178 if (fArmsSeparationAngle == 0 || d < fInitialRadius) {
179 if (fInternalRegionRadius > 0 && d < fInternalRegionRadius) return 1;
180
181 return 0;
182 }
183
184 Double_t cos_angle = y / d;
185
186 if (x >= 0) {
187 int region = 1;
188 for (unsigned int n = 0; n < fPositiveRanges.size() - 1; n++) {
189 if (cos_angle < fPositiveRanges[n].second && cos_angle > fPositiveRanges[n + 1].first)
190 return region % fMaxRegions + 1;
191 region++;
192 }
193 if (cos_angle < fPositiveRanges.back().second && cos_angle >= -1) return region % fMaxRegions + 1;
194
195 } else {
196 int region = fPositiveRanges.size() + 1;
197
198 if (cos_angle < fNegativeRanges[0].first && cos_angle >= -1) return region % fMaxRegions + 1;
199 region++;
200
201 for (unsigned int n = 0; n < fNegativeRanges.size() - 1; n++) {
202 if (cos_angle > fNegativeRanges[n].second && cos_angle < fNegativeRanges[n + 1].first)
203 return region % fMaxRegions + 1;
204 region++;
205 }
206 }
207
208 return 0;
209}
210
217 if (fArmsSeparationAngle <= 0) return;
218
219 fPositiveRanges.clear();
220 fNegativeRanges.clear();
221
222 std::pair<Double_t, Double_t> additional_negative = {-1, -1};
223
224 // The angle parameter could introduce an offset but we let finally this task to TRestPatternMask
225 Double_t angle = 0;
226 do {
227 Double_t angle_down = angle - fArmsWidth / 2.;
228 Double_t angle_up = angle + fArmsWidth / 2.;
229
230 if (angle_down < 0) {
231 additional_negative = {2 * TMath::Pi() + angle_down, 2 * TMath::Pi()};
232 fPositiveRanges.push_back({0, angle_up});
233
234 } else if (angle_up > TMath::Pi() && angle_down < TMath::Pi()) {
235 fPositiveRanges.push_back({angle_down, TMath::Pi()});
236 fNegativeRanges.push_back({TMath::Pi(), angle_up});
237 } else if (angle_up < TMath::Pi()) {
238 fPositiveRanges.push_back({angle_down, angle_up});
239 } else if (angle_down >= TMath::Pi()) {
240 fNegativeRanges.push_back({angle_down, angle_up});
241 }
242
243 angle += fArmsSeparationAngle;
244
245 } while (angle + 1.e-3 < 2 * TMath::Pi());
246
247 if (additional_negative.first != -1 && additional_negative.second != -1)
248 fNegativeRanges.push_back(additional_negative);
249
250 RESTDebug << "Printing positive spider angles" << RESTendl;
251 RESTDebug << "-------------------------------" << RESTendl;
252 for (unsigned int n = 0; n < fPositiveRanges.size(); n++) {
253 RESTDebug << "n : " << n << " from : " << 180 * fPositiveRanges[n].first / TMath::Pi() << " to "
254 << 180 * fPositiveRanges[n].second / TMath::Pi() << RESTendl;
255 }
256
257 RESTDebug << "Printing negative spider angles" << RESTendl;
258 RESTDebug << "-------------------------------" << RESTendl;
259 for (unsigned int n = 0; n < fNegativeRanges.size(); n++) {
260 RESTDebug << "n : " << n << " from : " << 180 * fNegativeRanges[n].first / TMath::Pi() << " to "
261 << 180 * fNegativeRanges[n].second / TMath::Pi() << RESTendl;
262 }
263
264 for (unsigned int n = 0; n < fNegativeRanges.size(); n++) {
265 fNegativeRanges[n].first = TMath::Cos(fNegativeRanges[n].first);
266 fNegativeRanges[n].second = TMath::Cos(fNegativeRanges[n].second);
267 }
268
269 for (unsigned int n = 0; n < fPositiveRanges.size(); n++) {
270 fPositiveRanges[n].first = TMath::Cos(fPositiveRanges[n].first);
271 fPositiveRanges[n].second = TMath::Cos(fPositiveRanges[n].second);
272 }
273
274 RESTDebug << "Printing positive spider angles" << RESTendl;
275 RESTDebug << "-------------------------------" << RESTendl;
276 for (unsigned int n = 0; n < fPositiveRanges.size(); n++) {
277 RESTDebug << "n : " << n << " from : " << fPositiveRanges[n].first << " to "
278 << fPositiveRanges[n].second << RESTendl;
279 }
280
281 RESTDebug << "Printing negative spider cosines" << RESTendl;
282 RESTDebug << "--------------------------------" << RESTendl;
283 for (unsigned int n = 0; n < fNegativeRanges.size(); n++) {
284 RESTDebug << "n : " << n << " from : " << fNegativeRanges[n].first << " to "
285 << fNegativeRanges[n].second << RESTendl;
286 }
287}
288
294
296 RESTMetadata << "----" << RESTendl;
297}
298
305 RESTMetadata << "----" << RESTendl;
307}
308
314 RESTMetadata << " - Arms separation angle : " << fArmsSeparationAngle * units("degrees") << " degrees"
315 << RESTendl;
316 RESTMetadata << " - Arms angular width : " << fArmsWidth * units("degrees") << " degrees" << RESTendl;
317 RESTMetadata << " - Spider start radius : " << fInitialRadius * units("cm") << " cm" << RESTendl;
318 RESTMetadata << " - Internal region radius : " << fInternalRegionRadius * units("cm") << " cm"
319 << RESTendl;
320
321 if (fPositiveRanges.size() > 0) {
322 RESTMetadata << "-------------------------------" << RESTendl;
323 for (unsigned int n = 0; n < fPositiveRanges.size(); n++) {
324 RESTDebug << "n : " << n << " from : " << 180 * fPositiveRanges[n].first / TMath::Pi() << " to "
325 << 180 * fPositiveRanges[n].second / TMath::Pi() << RESTendl;
326 }
327
328 RESTMetadata << "Positive ranges : {";
329 for (unsigned int n = 0; n < fPositiveRanges.size(); n++) {
330 if (n > 0) RESTMetadata << ", ";
331 RESTMetadata << "(" << fPositiveRanges[n].first << ", " << fPositiveRanges[n].second << ")";
332 }
333 RESTMetadata << "}" << RESTendl;
334
335 RESTMetadata << "Negative ranges : {";
336 for (unsigned int n = 0; n < fNegativeRanges.size(); n++) {
337 if (n > 0) RESTMetadata << ", ";
338 RESTMetadata << "(" << fNegativeRanges[n].first << ", " << fNegativeRanges[n].second << ")";
339 }
340 RESTMetadata << "}" << RESTendl;
341 }
342}
endl_t RESTendl
Termination flag object for TRestStringOutput.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string fConfigFileName
Full name of the rml file.
An abstract class used to encapsulate different mask pattern class definitions.
void SetType(const std::string &type)
It defines the mask type. To be called by the inherited class constructor.
Int_t fMaxRegions
The maximum number of regions allowed in each mask.
void PrintMetadata() override
Prints on screen the information about the metadata members of TRestPatternMask.
virtual Int_t GetRegion(Double_t &x, Double_t &y)
To be implemented at the inherited class with the pattern and region identification logic.
void PrintCommonPatternMembers()
Prints on screen the information about the metadata members without header.
A class used to define and generate a spider structure mask.
void GenerateSpider()
This method is used to initialize the spider arm angles data members that are used to determine if a ...
Double_t fInternalRegionRadius
Radius of an internal circular region defined inside the fInitialRadius. If 0, there will be no regio...
void PrintMetadata() override
Prints on screen the complete information about the metadata members from this class.
virtual Int_t GetRegion(Double_t &x, Double_t &y) override
It returns a number identifying the region where the particle with coordinates (x,...
Double_t fArmsSeparationAngle
The angle between two consecutive spider arms measured in radians.
std::vector< std::pair< Double_t, Double_t > > fPositiveRanges
Used internally to define the forbidden (cosine) angular ranges imposed by the spider structure (0,...
void PrintMask() override
Prints on screen the information about the metadata members from this class, including common pattern...
Double_t fArmsWidth
The width of each specific spider arm. Measured in radians. Default is 2.5 degrees.
Double_t fInitialRadius
The spider structure will be effective from this radius, in mm. Default is from 20 mm.
std::vector< std::pair< Double_t, Double_t > > fNegativeRanges
Used internally to define the forbidden (cosine) ang. ranges imposed by the spider structure (Pi,...
void Initialize() override
Function to initialize input/output event members and define the section name.
void PrintMaskMembers() override
Prints on screen the information about the metadata members from this class, excluding common metadat...
~TRestSpiderMask()
Default destructor.
TRestSpiderMask()
Default constructor.
@ REST_Info
+show most of the information for each steps