-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from rest-for-physics/jgalan_smear_review2
Reviewing TRestDetectorHitsSmearingProcess
- Loading branch information
Showing
5 changed files
with
133 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,121 @@ | ||
///______________________________________________________________________________ | ||
///______________________________________________________________________________ | ||
///______________________________________________________________________________ | ||
/************************************************************************* | ||
* This file is part of the REST software framework. * | ||
* * | ||
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) * | ||
* For more information see http://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 http://www.gnu.org/licenses/. * | ||
* For the list of contributors see $REST_PATH/CREDITS. * | ||
*************************************************************************/ | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
/// TRestDetectorHitsSmearingProcess will introduce a stochastic smearing on the | ||
/// energy of the hits for each event. The total energy of each event will be | ||
/// re-distributed following a gaussian shaped function. | ||
/// | ||
/// The energy resolution will follow a root square law with the energy | ||
/// using the `energyReference` and the `resolutionReference` as a pivoting | ||
/// point. | ||
/// | ||
/// RESTSoft : Software for Rare Event Searches with TPCs | ||
/// Therefore, the process defines only two parameters, one being the energy | ||
/// at wich the energy resolution is "known", and the FWHM in percentage at | ||
/// that given energy, `resolutionReference`. | ||
/// | ||
/// TRestDetectorHitsSmearingProcess.cxx | ||
/// \code | ||
/// <addProcess type="TRestDetectorHitsSmearingProcess" name="smear" | ||
/// title="Energy resolution smearing"> | ||
/// <parameter name="energyReference" value="250keV" /> | ||
/// <parameter name="resolutionReference" value="15" /> | ||
/// </addProcess> | ||
/// \endcode | ||
/// | ||
/// Template to use to design "event process" classes inherited from | ||
/// TRestDetectorHitsSmearingProcess | ||
/// How to use: replace TRestDetectorHitsSmearingProcess by your name, | ||
/// fill the required functions following instructions and add all | ||
/// needed additional members and funcionality | ||
/// The following image is the result of smearing the energy of an electron | ||
/// gun of 250keV. It was produced using the exercise 3.2 inside the | ||
/// [day3/session2](https://github.com/rest-for-physics/rest-school/tree/master/day3/session2) | ||
/// at the rest-school repository. | ||
/// | ||
/// \htmlonly <style>div.image img[src="smear.png"]{width:500px;}</style> \endhtmlonly | ||
/// ![The result of applying a 15% energy resolution at 250keV](smear.png) | ||
/// | ||
///-------------------------------------------------------------------------- | ||
/// | ||
/// RESTsoft - Software for Rare Event Searches with TPCs | ||
/// | ||
/// History of developments: | ||
/// | ||
/// 2016-February: First implementation of TRestDetectorHitsSmearingProcess | ||
/// \author Javier G. Garza | ||
/// | ||
/// 2023-January: This class has been documented | ||
/// \author Javier Galan - javier.galan@unizar.es | ||
/// | ||
/// \class TRestDetectorHitsSmearingProcess | ||
/// | ||
/// <hr> | ||
/// | ||
/// feb 2016: First concept | ||
/// Created as part of the conceptualization of existing REST | ||
/// software. | ||
/// Javier G. Garza | ||
///_______________________________________________________________________________ | ||
|
||
#include "TRestDetectorHitsSmearingProcess.h" | ||
|
||
using namespace std; | ||
|
||
ClassImp(TRestDetectorHitsSmearingProcess); | ||
|
||
/////////////////////////////////////////////// | ||
/// \brief Default constructor | ||
/// | ||
TRestDetectorHitsSmearingProcess::TRestDetectorHitsSmearingProcess() { Initialize(); } | ||
|
||
TRestDetectorHitsSmearingProcess::TRestDetectorHitsSmearingProcess(const char* configFilename) { | ||
Initialize(); | ||
|
||
if (LoadConfigFromFile(configFilename)) { | ||
LoadDefaultConfig(); | ||
} | ||
|
||
PrintMetadata(); | ||
} | ||
|
||
/////////////////////////////////////////////// | ||
/// \brief Default destructor | ||
/// | ||
TRestDetectorHitsSmearingProcess::~TRestDetectorHitsSmearingProcess() { | ||
delete fHitsOutputEvent; | ||
delete fOutputEvent; | ||
// TRestDetectorHitsSmearingProcess destructor | ||
} | ||
|
||
void TRestDetectorHitsSmearingProcess::LoadDefaultConfig() { | ||
SetTitle("Default config"); | ||
|
||
fEnergyRef = 5.9; | ||
fResolutionAtERef = 15.0; | ||
} | ||
|
||
/////////////////////////////////////////////// | ||
/// \brief Function to initialize input/output event members and define the section name | ||
/// | ||
void TRestDetectorHitsSmearingProcess::Initialize() { | ||
SetSectionName(this->ClassName()); | ||
SetLibraryVersion(LIBRARY_VERSION); | ||
|
||
fEnergyRef = 5.9; | ||
fResolutionAtERef = 15.0; | ||
|
||
fHitsInputEvent = nullptr; | ||
fHitsOutputEvent = new TRestDetectorHitsEvent(); | ||
|
||
fRandom = nullptr; | ||
} | ||
|
||
void TRestDetectorHitsSmearingProcess::LoadConfig(const string& configFilename, const string& name) { | ||
if (LoadConfigFromFile(configFilename, name)) { | ||
LoadDefaultConfig(); | ||
} | ||
|
||
PrintMetadata(); | ||
|
||
fGas = GetMetadata<TRestDetectorGas>(); | ||
fInputEvent = nullptr; | ||
fOutputEvent = new TRestDetectorHitsEvent(); | ||
} | ||
|
||
void TRestDetectorHitsSmearingProcess::InitProcess() { | ||
// Function to be executed once at the beginning of process | ||
// (before starting the process of the events) | ||
|
||
// Start by calling the InitProcess function of the abstract class. | ||
// Comment this if you don't want it. | ||
// TRestEventProcess::InitProcess(); | ||
if (fRandom != nullptr) delete fRandom; | ||
fRandom = new TRandom3(fSeed); | ||
fSeed = fRandom->TRandom::GetSeed(); | ||
} | ||
|
||
/////////////////////////////////////////////// | ||
/// \brief The main processing event function | ||
/// | ||
TRestEvent* TRestDetectorHitsSmearingProcess::ProcessEvent(TRestEvent* inputEvent) { | ||
fHitsInputEvent = (TRestDetectorHitsEvent*)inputEvent; | ||
fHitsOutputEvent->SetEventInfo(fHitsInputEvent); | ||
fInputEvent = (TRestDetectorHitsEvent*)inputEvent; | ||
fOutputEvent->SetEventInfo(fInputEvent); | ||
|
||
Double_t eDep = fHitsInputEvent->GetTotalEnergy(); | ||
Double_t eDep = fInputEvent->GetTotalEnergy(); | ||
Double_t eRes = fResolutionAtERef * TMath::Sqrt(fEnergyRef / eDep) / 2.35 / 100.0; | ||
|
||
Double_t gain = fRandom->Gaus(1.0, eRes); | ||
for (unsigned int hit = 0; hit < fHitsInputEvent->GetNumberOfHits(); hit++) | ||
fHitsOutputEvent->AddHit(fHitsInputEvent->GetX(hit), fHitsInputEvent->GetY(hit), | ||
fHitsInputEvent->GetZ(hit), fHitsInputEvent->GetEnergy(hit) * gain, | ||
fHitsInputEvent->GetTime(hit), fHitsInputEvent->GetType(hit)); | ||
|
||
return fHitsOutputEvent; | ||
} | ||
|
||
void TRestDetectorHitsSmearingProcess::EndProcess() { | ||
// Function to be executed once at the end of the process | ||
// (after all events have been processed) | ||
|
||
// Start by calling the EndProcess function of the abstract class. | ||
// Comment this if you don't want it. | ||
// TRestEventProcess::EndProcess(); | ||
} | ||
for (unsigned int hit = 0; hit < fInputEvent->GetNumberOfHits(); hit++) | ||
fOutputEvent->AddHit(fInputEvent->GetX(hit), fInputEvent->GetY(hit), fInputEvent->GetZ(hit), | ||
fInputEvent->GetEnergy(hit) * gain, fInputEvent->GetTime(hit), | ||
fInputEvent->GetType(hit)); | ||
|
||
void TRestDetectorHitsSmearingProcess::InitFromConfigFile() { | ||
fEnergyRef = GetDblParameterWithUnits("energyReference"); | ||
fResolutionAtERef = StringToDouble(GetParameter("resolutionReference")); | ||
fRandom = new TRandom3(StringToDouble(GetParameter("seed", "0"))); | ||
return fOutputEvent; | ||
} |