7 #include "G4EventManager.hh"
9 #include "G4SDManager.hh"
10 #include "G4DigiManager.hh"
12 #include "G4RotationMatrix.hh"
13 #include "G4ThreeVector.hh"
14 #include "G4LogicalVolumeStore.hh"
25 #ifndef WCSIMWCADDDARKNOISE_VERBOSE
30 #define NPMTS_VERBOSE 10
33 #ifndef HYPER_VERBOSITY
39 G4String detectorElement)
40 :G4VDigitizerModule(name), fCalledAddDarkNoise(false), myDetector(inDetector), detectorElement(detectorElement)
65 G4String WCCollectionName;
68 else G4cout <<
"### detectorElement undefined ..." << G4endl;
71 double const conversion_to_kHz = 1000000;
73 double defaultPMTDarkRate = PMT->
GetDarkRate() * conversion_to_kHz;
93 G4DigiManager* DigiMan = G4DigiManager::GetDMpointer();
98 G4String thecollectionName;
99 if(
detectorElement==
"tank") thecollectionName=
"WCRawPMTSignalCollection";
100 else if(
detectorElement==
"OD") thecollectionName=
"WCRawPMTSignalCollection_OD";
101 else G4cout <<
"### detectorElement undefined ..." << G4endl;
102 G4int WCHCID = DigiMan->GetDigiCollectionID(thecollectionName);
108 #ifdef HYPER_VERBOSITY
109 if(
detectorElement==
"OD"){G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoise ☆ retrieved hit collection (WCSimWCDigitsCollection*)"<<thecollectionName<<
" which has "<<WCHCPMT->entries()<<
" entries"<<G4endl;}
112 G4String thetriggertype=
"";
119 if(thetriggertype==
"TankDigits"){
122 int WCHCID_tank = DigiMan->GetDigiCollectionID(
"WCRawPMTSignalCollection");
125 #ifdef HYPER_VERBOSITY
126 if(
detectorElement==
"OD"){ G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoise ☆ retrieved hit collection (WCSimWCDigitsCollection*)WCRawPMTSignalCollection for finding dark noise windows, which has "<<WCHCPMT_tank->entries()<<
" entries"<<G4endl;}
131 if (((WCHCPMT != NULL)||(thetriggertype==
"TankDigits"&&WCHCPMT_tank!=NULL)) && (this->
PMTDarkRate > 1
E-307)) {
136 if(thetriggertype==
"TankDigits"){
139 #ifdef HYPER_VERBOSITY
140 if(
detectorElement==
"OD") G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoise ☆ calling FindDarkNoiseRanges() with tank raw collection and darkwindow size"<<G4endl;
153 #ifdef HYPER_VERBOSITY
154 if(
detectorElement==
"OD") G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoise ☆ adding dark noise hits in "<<
result.size()<<
" window(s) around found digits."<<G4endl;
156 int windowfordarknoise=0;
158 for(std::vector<std::pair<double, double> >::iterator it2 =
result.begin(); it2 !=
result.end(); it2++) {
159 #ifdef HYPER_VERBOSITY
160 if(
detectorElement==
"OD") G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoise ☆ adding dark noise in window "<<windowfordarknoise<<G4endl; windowfordarknoise++;
175 G4int number_entries = WCHCPMT->entries();
177 #ifdef HYPER_VERBOSITY
178 if(
detectorElement==
"OD")G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoiseBeforeDigi ☆ adding dark noise to collection of "<<number_entries<<
" entries"<<G4endl;
183 else G4cout <<
"### detectorElement undefined ..." << G4endl;
184 const G4int number_pmts=thenum_pmts;
185 int *PMTindex =
new int [number_pmts+1];
188 for (
int l=0; l<number_pmts+1; l++){
195 for (
int g=0; g<number_entries; g++){
196 G4int tube = (*WCHCPMT)[g]->GetTubeID();
199 PMTindex[tube] += (*WCHCPMT)[g]->GetTotalPe();
200 num_hit_b4 += (*WCHCPMT)[g]->GetTotalPe();
207 std::vector<WCSimPmtInfo*> *pmts;
210 else G4cout <<
"### detectorElement undefined ..." << G4endl;
215 std::vector<int> list;
216 list.assign( number_pmts+1, 0 );
218 for(
int h = 0; h < number_entries; h++ ) {
219 list[(*WCHCPMT)[h]->GetTubeID()] = h+1;
223 double current_time = 0;
226 double windowsize = num2 - num1;
228 G4DigiManager* DMman = G4DigiManager::GetDMpointer();
231 G4String thewcpmtname;
234 else G4cout <<
"### detectorElement undefined ..." << G4endl;
237 #ifdef HYPER_VERBOSITY
238 if(
detectorElement==
"OD"){G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoiseBeforeDigi ☆ getting (WCSimWCPMT*)"<<thewcpmtname<<G4endl;}
246 int nnoispmt = CLHEP::RandPoisson::shoot(ave);
247 G4String thecollectionName;
248 if(
detectorElement==
"tank") thecollectionName=
"WCRawPMTSignalCollection";
249 else if(
detectorElement==
"OD") thecollectionName=
"WCRawPMTSignalCollection_OD";
250 else G4cout <<
"### detectorElement undefined ..." << G4endl;
251 #ifdef HYPER_VERBOSITY
252 if(
detectorElement==
"OD"){G4cout<<
"WCSimWCAddDarkNoise::AddDarkNoiseBeforeDigi ☆ adding "<<nnoispmt<<
" dark hits to "<<thecollectionName<<G4endl;}
255 #ifdef WCSIMWCADDDARKNOISE_VERBOSE
256 G4cout <<
"WCSimWCAddDarkNoise::AddDarkNoiseBeforeDigi Going to add " << nnoispmt <<
" dark noise hits in time window [" << num1 <<
"," << num2 <<
"] duration " << num2 - num1 << G4endl;
258 for(
int i = 0; i < nnoispmt; i++ )
262 current_time = num1 + G4UniformRand()*windowsize;
266 int noise_pmt =
static_cast<int>( G4UniformRand() * number_pmts ) + 1;
268 if( list[ noise_pmt ] == 0 )
280 else G4cout <<
"### detectorElement undefined ..." << G4endl;
299 G4RotationMatrix pmt_rotation(hit_rot[0], hit_rot[1], hit_rot[2]);
300 G4ThreeVector pmt_position(hit_pos[0], hit_pos[1], hit_pos[2]);
301 ahit->
SetRot(pmt_rotation);
302 ahit->
SetPos(pmt_position);
303 ahit->
SetTime(PMTindex[noise_pmt],current_time);
306 ahit->
SetPe(PMTindex[noise_pmt],pe);
308 ahit->
AddPe(current_time);
309 WCHCPMT->insert(ahit);
310 PMTindex[noise_pmt]++;
312 list[ noise_pmt ] = number_entries;
313 #ifdef WCSIMWCADDDARKNOISE_VERBOSE
315 G4cout <<
"WCSimWCAddDarkNoise::AddDarkNoiseBeforeDigi Added NEW DIGI with dark noise hit at time " << current_time <<
" to PMT " << noise_pmt << G4endl;
319 (*WCHCPMT)[ list[noise_pmt]-1 ]->AddPe(current_time);
321 (*WCHCPMT)[ list[noise_pmt]-1 ]->SetPe(PMTindex[noise_pmt],pe);
322 (*WCHCPMT)[ list[noise_pmt]-1 ]->SetTime(PMTindex[noise_pmt],current_time);
323 (*WCHCPMT)[ list[noise_pmt]-1 ]->SetPreSmearTime(PMTindex[noise_pmt],current_time);
324 (*WCHCPMT)[ list[noise_pmt]-1 ]->SetParentID(PMTindex[noise_pmt],-1);
325 PMTindex[noise_pmt]++;
326 #ifdef WCSIMWCADDDARKNOISE_VERBOSE
328 G4cout <<
"WCSimWCAddDarkNoise::AddDarkNoiseBeforeDigi Added to exisiting digi a dark noise hit at time " << current_time <<
" to PMT " << noise_pmt << G4endl;
343 for (
int g=0; g<WCHCPMT->entries(); g++){
344 for (
int gp=0; gp<(*WCHCPMT)[g]->GetTotalPe(); gp++){
345 double time = (*WCHCPMT)[g]->GetTime(gp);
348 double t1=time - width/2.;
349 double t2=time + width/2.;
350 ranges.push_back(std::pair<double, double>(t1, t2));
354 #ifdef HYPER_VERBOSITY
355 if(
detectorElement==
"mrd") G4cout<<
"WCSimWCAddDarkNoise::FindDarkNoiseRanges ☆ "<<
ranges.size()<<
" windows around digits found before pruning."<<G4endl;
370 result.push_back(std::make_pair(0.,0.));
377 std::vector<std::pair<double, double> >::iterator it =
ranges.begin();
378 std::pair<double, double> current = *(it)++;
379 for( ; it !=
ranges.end(); it++) {
380 if (current.second >= it->first){
381 current.second = std::max(current.second, it->second);
384 result.push_back(current);
388 result.push_back(current);
void SetPreSmearTime(G4int gate, G4double T)
void SetLogicalVolume(G4LogicalVolume *logV)
void SetDarkHigh(string tag, double iDarkHigh)
std::vector< std::pair< double, double > > ranges
void SetRot(G4RotationMatrix rotMatrix)
G4int GetTotalNumODPmts()
void AddDarkNoiseBeforeDigi(WCSimWCDigitsCollection *WCHCPMT, double num1, double num2)
void SetPMTDarkDefaults()
void SetTrackID(G4int track)
void SetTubeID(G4int tube)
void SetDarkLow(string tag, double iDarkLow)
WCSimPMTObject * GetPMTPointer(G4String CollectionName)
WCSimDarkRateMessenger * DarkRateMessenger
void SetPe(G4int gate, G4double Q)
G4TDigiCollection< WCSimWCDigi > WCSimWCDigitsCollection
G4String GetIDCollectionName()
The base class for WCSim triggering algorithms.
void SetPMTDarkRate(string tag, double iPMTDarkRate)
G4String GetTriggerClassName()
Get the trigger class name.
static WCSimDarkRateMessenger * GetInstance()
WCSimDetectorConstruction * myDetector
void SetDarkWindow(string tag, double iDarkWindow)
std::vector< std::pair< double, double > > result
virtual G4double GetDarkRateConversionFactor()=0
WCSimWCAddDarkNoise(G4String name, WCSimDetectorConstruction *, G4String)
G4String GetDetectorName()
G4String GetODCollectionName()
void AddPe(G4double hitTime)
std::vector< WCSimPmtInfo * > * Get_Pmts()
std::vector< WCSimPmtInfo * > * Get_ODPmts()
void SetPos(G4ThreeVector xyz)
void SetTime(G4int gate, G4double T)
void FindDarkNoiseRanges(WCSimWCDigitsCollection *WCHCPMT, double width)
virtual G4double GetDarkRate()=0
void SetConvRate(string tag, double iConvRate)
void SetParentID(G4int gate, G4int parent)
void SaveOptionsToOutput(WCSimRootOptions *wcopt, string tag)
void RemoveDarkRateInstance(G4String detectorElement)
double E[MAX_N_PRIMARIES]
void SetDarkMode(string tag, int iDarkMode)
void AddDarkRateInstance(WCSimWCAddDarkNoise *darkratepoint, G4String detectorElement)