WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimDarkRateMessenger.cc
Go to the documentation of this file.
2 #include "WCSimWCAddDarkNoise.hh"
3 
4 #include "G4UIdirectory.hh"
5 #include "G4UIcommand.hh"
6 #include "G4UIcmdWithADoubleAndUnit.hh"
7 #include "G4UIcmdWithADouble.hh"
8 #include "G4UIcmdWithAnInteger.hh"
9 #include "G4UIcmdWithAString.hh"
10 
12  : WCSimAddDarkNoise(darkratepoint), WCSimDir(0), SetFrequency(0), SetConversionRate(0), SetDarkMode(0), SetDarkLow(0), SetDarkHigh(0), SetDarkWindow(0), SetDetectorElement(0)
13 {
14  //Initialize();
15 }
16 
18 
20  //G4cout<<"making the static instance"<<G4endl;
21  //static WCSimDarkRateMessenger* iInstance = new WCSimDarkRateMessenger(0);
22  if(iInstance==NULL){
24  }
25  //G4cout<<"returning static instance at "<<iInstance<<G4endl;
26  return iInstance;
27 }
28 
30 {
31  G4cout << "Initializing Dark Rate Messenger for detector element " << detectorElement << G4endl;
32  initaliseString = " (this is a default set; it may be overwritten by user commands)";
33 
34  if(WCSimDir==0){WCSimDir = new G4UIdirectory("/DarkRate/");}
35  WCSimDir->SetGuidance("Commands to change the dark noise frequency of the simulation");
36 
37  double const conversion_to_kHz = 1000000;
38  double defaultFrequency = 0;
39  if(SetFrequency==0){SetFrequency = new G4UIcmdWithADoubleAndUnit("/DarkRate/SetDarkRate",this);}
40  SetFrequency->SetGuidance("Commands to change the dark noise frequency of the simulation");
41  SetFrequency->SetParameterName("DarkRate",false);
42  SetFrequency->SetDefaultValue(defaultFrequency * conversion_to_kHz);
43  //kilohertz is 10e-6 (CLHEP units: 1kHz = 1000 / (1e9 ns) = 1e-6 as ns := 1.)
44  SetFrequency->SetUnitCategory("Frequency");
45  SetFrequency->SetDefaultUnit("kHz");
46  SetFrequency->SetUnitCandidates("Hz kHz MHz GHz");
47 
48 
49  double defaultConvRate = 1;
50  if(SetConversionRate==0){ SetConversionRate = new G4UIcmdWithADouble("/DarkRate/SetConvert",this);}
51  SetConversionRate->SetGuidance("Calibrate the frequency of dark noise before applying the threshold (typically 0.25pe)");
52  SetConversionRate->SetParameterName("DigiCorr",false);
53  SetConversionRate->SetDefaultValue(defaultConvRate);
54 
55  //Mode 0 - Add dark rate in window defined by /DarkRate/SetDarkLow and /DarkRate/SetDarkHigh
56  //If not set default is 0 and 100000ns
57  //Mode 1 - Add dark rate to a window of size /DarkRate/SetDarkWindow around each hit
58  int defaultDarkMode = 0;
59  if(SetDarkMode==0){SetDarkMode = new G4UIcmdWithAnInteger("/DarkRate/SetDarkMode",this);}
60  SetDarkMode->SetGuidance("Set the mode of adding dark noise to the event");
61  SetDarkMode->SetParameterName("DarkMode",false);
62  SetDarkMode->SetDefaultValue(defaultDarkMode);
63  SetNewValue(SetDarkMode, G4UIcommand::ConvertToString(defaultDarkMode));
64 
65  double defaultDarkLow = 0;
66  if(SetDarkLow==0){SetDarkLow = new G4UIcmdWithADoubleAndUnit("/DarkRate/SetDarkLow",this);}
67  SetDarkLow->SetGuidance("Set the lower GEANT time limit to add dark noise");
68  SetDarkLow->SetParameterName("DarkLow",false);
69  SetDarkLow->SetDefaultValue(defaultDarkLow);
70  SetDarkLow->SetUnitCategory("Time");
71  SetDarkLow->SetDefaultUnit("ns");
72  SetNewValue(SetDarkLow, G4UIcommand::ConvertToString(defaultDarkLow, "ns"));
73 
74  double defaultDarkHigh = 100000;
75  if(SetDarkHigh==0){SetDarkHigh = new G4UIcmdWithADoubleAndUnit("/DarkRate/SetDarkHigh",this);}
76  SetDarkHigh->SetGuidance("Set the upper GEANT time limit to add dark noise");
77  SetDarkHigh->SetParameterName("DarkHigh",false);
78  SetDarkHigh->SetDefaultValue(defaultDarkHigh);
79  SetDarkHigh->SetUnitCategory("Time");
80  SetDarkHigh->SetDefaultUnit("ns");
81  SetNewValue(SetDarkHigh, G4UIcommand::ConvertToString(defaultDarkHigh, "ns"));
82 
83  double defaultDarkWindow = 5000;
84  if(SetDarkWindow==0){SetDarkWindow = new G4UIcmdWithADoubleAndUnit("/DarkRate/SetDarkWindow",this);}
85  SetDarkWindow->SetGuidance("Set the window width to add dark noise");
86  SetDarkWindow->SetParameterName("DarkWindow",false);
87  SetDarkWindow->SetDefaultValue(defaultDarkWindow);
88  SetDarkWindow->SetUnitCategory("Time");
89  SetDarkWindow->SetDefaultUnit("ns");
90  SetNewValue(SetDarkWindow, G4UIcommand::ConvertToString(defaultDarkWindow, "ns"));
91 
92  G4String defaultDetectorElement = "tank";
93  if(SetDetectorElement==0){ SetDetectorElement = new G4UIcmdWithAString("/DarkRate/SetDetectorElement", this); }
94  SetDetectorElement->SetGuidance("Set the detector element for which trigger settings will be applied");
95  G4String theguidance = "Available choices are:\n";
96  G4String thecandidates="";
97  for(std::map<std::string, WCSimWCAddDarkNoise*>::iterator it=darknoiseptrs.begin(); it!=darknoiseptrs.end(); ++it){
98  theguidance+=it->first; theguidance+="\n";
99  thecandidates+=it->first; thecandidates+=" ";
100  }
101  SetDetectorElement->SetGuidance(theguidance);
102  SetDetectorElement->SetCandidates(thecandidates);
103  SetDetectorElement->SetParameterName("detectorElement", false);
104  SetDetectorElement->AvailableForStates(G4State_PreInit, G4State_Idle);
105  SetDetectorElement->SetDefaultValue(defaultDetectorElement);
106 
107  initaliseString = "";
108 }
109 
111 {
112 
113  delete SetFrequency;
114  delete SetConversionRate;
115  delete SetDarkMode;
116  delete SetDarkLow;
117  delete SetDarkHigh;
118  delete SetDarkWindow;
119  delete WCSimDir;
120  delete SetDetectorElement;
121 }
122 
123 void WCSimDarkRateMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
124 {
125  if(command == SetFrequency){
126  // Since kHz is 10e-3 for this class we must multiply by a 10e6 factor
127  // to make default units in kHz
128  // ToDo: make this consistent with CLHEP unit system. Makes it easier to just using CLHEP!
129  double const conversion_to_kHz = 1000000;
130  WCSimAddDarkNoise->SetDarkRate(conversion_to_kHz * SetFrequency->GetNewDoubleValue(newValue));
131  G4cout << "Setting Dark Rate " << conversion_to_kHz * SetFrequency->GetNewDoubleValue(newValue)
132  << initaliseString.c_str() << G4endl;
133  }
134  else if(command == SetConversionRate){
135  WCSimAddDarkNoise->SetConversion(SetConversionRate->GetNewDoubleValue(newValue));
136  G4cout << "Setting Dark Rate Conversion value " << SetConversionRate->GetNewDoubleValue(newValue)
137  << initaliseString.c_str() << G4endl;
138  }
139  else if(command == SetDarkMode){
140  WCSimAddDarkNoise->SetDarkMode(SetDarkMode->GetNewIntValue(newValue));
141  G4cout << "Setting DarkMode value " << SetDarkMode->GetNewIntValue(newValue)
142  << initaliseString.c_str() << G4endl;
143  }
144  else if(command == SetDarkLow){
145  WCSimAddDarkNoise->SetDarkLow(SetDarkLow->GetNewDoubleValue(newValue));
146  G4cout << "Setting DarkLow value " << SetDarkLow->GetNewDoubleValue(newValue)
147  << initaliseString.c_str() << G4endl;
148  }
149  else if(command == SetDarkHigh){
150  WCSimAddDarkNoise->SetDarkHigh(SetDarkHigh->GetNewDoubleValue(newValue));
151  G4cout << "Setting DarkHigh value " << SetDarkHigh->GetNewDoubleValue(newValue)
152  << initaliseString.c_str() << G4endl;
153  }
154  else if(command == SetDarkWindow){
155  WCSimAddDarkNoise->SetDarkWindow(SetDarkWindow->GetNewDoubleValue(newValue));
156  G4cout << "Setting DarkWindow value " << SetDarkWindow->GetNewDoubleValue(newValue)
157  << initaliseString.c_str() << G4endl;
158  }
159  else if(command == SetDetectorElement){
160  if(darknoiseptrs.count(newValue)>0){
162  G4cout << "Setting detectorElement value " << newValue
163  << initaliseString.c_str() << G4endl;
164  }
165  }
166 }
167 
168 void WCSimDarkRateMessenger::AddDarkRateInstance(WCSimWCAddDarkNoise* darkratepoint, G4String detectorElementin){
169  if(darknoiseptrs.count(detectorElementin)>0){
170  G4cout<<"new dark rate messenger for existing detector Element "<<detectorElementin<<G4endl;
171  } else {
172  G4cout<<"added "<<detectorElementin<<" to the DarkRateMessenger"<<G4endl;
173  darknoiseptrs.insert(std::pair<std::string,WCSimWCAddDarkNoise*>(detectorElementin,darkratepoint));
174  WCSimAddDarkNoise=darkratepoint;
175  detectorElement=detectorElementin;
176  }
177 }
178 
179 void WCSimDarkRateMessenger::RemoveDarkRateInstance(G4String detectorElementin){
180  if(darknoiseptrs.count(detectorElementin)>0){
181  G4cout<<"deleting dark rate messenger for detector Element "<<detectorElementin<<G4endl;
182  std::map<std::string, WCSimWCAddDarkNoise*>::iterator thepointer = darknoiseptrs.find(detectorElementin);
183  darknoiseptrs.erase(thepointer);
184  if(darknoiseptrs.size()==0){ delete this; }
185  } else {
186  G4cout<<"Attempt to remove nonexistant element "<<detectorElementin<<" from DarkRateMessenger!"<<G4endl;
187  }
188 }
std::map< std::string, WCSimWCAddDarkNoise * > darknoiseptrs
void SetDarkMode(int imode)
void SetDarkWindow(int idarkwindow)
G4UIcmdWithADoubleAndUnit * SetFrequency
G4UIcmdWithADoubleAndUnit * SetDarkWindow
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetDarkLow(double idarklow)
G4UIcmdWithAString * SetDetectorElement
G4UIcmdWithADouble * SetConversionRate
G4UIcmdWithADoubleAndUnit * SetDarkLow
G4UIcmdWithAnInteger * SetDarkMode
static WCSimDarkRateMessenger * GetInstance()
void SetConversion(double iconvrate)
void SetDarkRate(double idarkrate)
WCSimDarkRateMessenger(WCSimWCAddDarkNoise *)
G4UIcmdWithADoubleAndUnit * SetDarkHigh
static WCSimDarkRateMessenger * iInstance
WCSimWCAddDarkNoise * WCSimAddDarkNoise
void SetDarkHigh(double idarkhigh)
void RemoveDarkRateInstance(G4String detectorElement)
void AddDarkRateInstance(WCSimWCAddDarkNoise *darkratepoint, G4String detectorElement)