WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimWCPMT.cc
Go to the documentation of this file.
1 #include "WCSimWCPMT.hh"
2 #include "WCSimWCDigi.hh"
3 #include "WCSimWCHit.hh"
4 
5 #include "G4EventManager.hh"
6 #include "G4Event.hh"
7 #include "G4SDManager.hh"
8 #include "G4DigiManager.hh"
9 #include "G4ios.hh"
10 #include "G4RotationMatrix.hh"
11 #include "G4ThreeVector.hh"
12 
14 #include "WCSimPmtInfo.hh"
15 #include "WCSimPMTObject.hh"
16 
17 
18 #include <vector>
19 // for memset
20 #include <cstring>
21 
22 #ifndef HYPER_VERBOSITY
23 // #define HYPER_VERBOSITY
24 #endif
25 
26 extern "C" void skrn1pe_(double* );
27 //extern "C" void rn1pe_(double* ); // 1Kton
28 
29 G4double WCSimWCPMT::first_time = 0;
30 
31 WCSimWCPMT::WCSimWCPMT(G4String name,
32  WCSimDetectorConstruction* myDetector,
33  G4String detectorElement)
34  :G4VDigitizerModule(name), detectorElement(detectorElement)
35 {
36  // G4String colName = "WCRawPMTSignalCollection";
37  // collectionName.push_back(colName);
38 
39  if(detectorElement=="tank") collectionName.push_back("WCRawPMTSignalCollection");
40  else if(detectorElement=="OD") collectionName.push_back("WCRawPMTSignalCollection_OD");
41  else G4cout << "detectorElement undefined..." << G4endl;
42  this->myDetector = myDetector;
43  DigiHitMapPMT.clear();
44 
45  #ifdef HYPER_VERBOSITY
46  if(detectorElement=="OD") G4cout<<"WCSimWCPMT::WCSimWCPMT ☆ recording collection name "<<collectionName[0]<<G4endl;
47  #endif
48 
49 }
50 
52 
53 }
54 
55 G4double WCSimWCPMT::rn1pe(){
56  // G4String WCIDCollectionName = myDetector->GetIDCollectionName();
57 
58  WCSimPMTObject * PMT;
59  G4String WCCollectionName;
62 
63  // PMT = myDetector->GetPMTPointer(WCIDCollectionName);
64 
65  G4int i;
66  G4double random = G4UniformRand();
67  G4double random2 = G4UniformRand();
68  G4double *qpe0;
69  qpe0 = PMT->Getqpe();
70  for(i = 0; i < 501; i++){
71 
72  if (random <= *(qpe0+i)) break;
73  }
74  if(i==500)
75  random = G4UniformRand();
76 
77  return (G4double(i-50) + random2)/22.83;
78 
79 }
80 
81 
83 {
84  // DigitsCollection = new WCSimWCDigitsCollection ("WCDigitizedCollectionPMT",collectionName[0]);
85  // G4String WCIDCollectionName = myDetector->GetIDCollectionName();
86 
87  // Create a DigitCollection and retrieve the appropriate hitCollection ID based on detectorElement
88  G4String WCCollectionName;
89  G4String DigitsCollectionName;
90  if(detectorElement=="tank"){
91  DigitsCollectionName="WCDigitizedCollection";
92  WCCollectionName = myDetector->GetIDCollectionName();
93  }else if(detectorElement=="OD"){
94  DigitsCollectionName="WCDigitizedCollection_OD";
95  WCCollectionName = myDetector->GetODCollectionName();
96  }
97 
98  DigitsCollection = new WCSimWCDigitsCollection (DigitsCollectionName,collectionName[0]);
99 
100  G4DigiManager* DigiMan = G4DigiManager::GetDMpointer();
101 
102  // Get the Associated Hit collection IDs
103  // G4int WCHCID = DigiMan->GetHitsCollectionID(WCIDCollectionName);
104  G4int WCHCID = DigiMan->GetHitsCollectionID(WCCollectionName);
105 
106  // The Hits collection
107  WCSimWCHitsCollection* WCHC =
108  (WCSimWCHitsCollection*)(DigiMan->GetHitsCollection(WCHCID));
109 
110  #ifdef HYPER_VERBOSITY
111  if(detectorElement=="OD"){
112  G4cout<<"WCSimWCPMT::Digitize ☆ Making digits collection (WCSimWCDigitsCollection*)"<<DigitsCollectionName<<" for "<<detectorElement
113  <<" and calling MakePeCorrection on "<<WCCollectionName<<" to fill it."<<G4endl;
114  }
115  #endif
116 
117  if (WCHC) {
118 
119  MakePeCorrection(WCHC);
120 
121  }
122 
123  #ifdef HYPER_VERBOSITY
124  if(detectorElement=="OD"){
125  G4cout<<"WCSimWCPMT::Digitize ☆ Storing "<<DigitsCollectionName<<" for "<<detectorElement
126  <<", which has "<<DigitsCollection->entries()<<" entries"<<G4endl;
127  }
128  #endif
129 
130  StoreDigiCollection(DigitsCollection);
131 
132 }
133 
134 
136 {
137  // Sort Hit times
138  std::sort(WCHC->GetVector()->begin(), WCHC->GetVector()->end(), WCSimWCHit::SortFunctor_Hit());
139 
140  //Get the PMT info for hit time smearing
141  // G4String WCIDCollectionName = myDetector->GetIDCollectionName();
142  // WCSimPMTObject * PMT = myDetector->GetPMTPointer(WCIDCollectionName);
143 
144  G4String WCCollectionName;
145  if(detectorElement=="tank") WCCollectionName = myDetector->GetIDCollectionName();
146  else if(detectorElement=="OD") WCCollectionName = myDetector->GetODCollectionName();
147 
148  WCSimPMTObject * PMT = myDetector->GetPMTPointer(WCCollectionName);
149 
150  // Correct timing to be within 1 sec (needed for radioactive decay as forcing the decay lead to some strange results)
151 
152 
153  #ifdef HYPER_VERBOSITY
154  if(detectorElement=="OD"){
155  G4cout<<"WCSimWCPMT::MakePeCorrection ☆ making PE correction for ";
156  }
157  if(WCHC){
158  G4cout<<WCHC->entries();
159  } else {
160  G4cout<<"0";
161  }
162  G4cout<<" entries"<<G4endl;
163  #endif
164 
165  for (G4int i=0; i < WCHC->entries(); i++)
166  {
167 
168  //G4double peCutOff = .3;
169  // MF, based on S.Mine's suggestion : global scaling factor applied to
170  // all the smeared charges.
171  // means that we need to increase the collected light by
172  // (efficiency-1)*100% to
173  // match K2K 1KT data : maybe due to PMT curvature ?
174 
175  //G4double efficiency = 0.985; // with skrn1pe (AP tuning) & 30% QE increase in stacking action
176 
177  // Get the information from the hit
178  G4int tube = (*WCHC)[i]->GetTubeID();
179  G4double peSmeared = 0.0;
180  G4double time_PMT, time_true;
181 
182  for (G4int ip =0; ip < (*WCHC)[i]->GetTotalPe(); ip++){
183 
184  // Reset the time to have "reasonnable" timing
185  // This modification is important in case of very late hit physics (such as in radioactive decays)
186  // for which time easy goes > 1e9 ns and cause bug in digitizer
187  // should not use /grdm/decayBiasProfile biasprofile.dat as it messes up all the timing of the decays, and force to use only one nucleus
188  if ( i == 0 && ip == 0 && RelativeHitTime /*&& (*WCHC)[i]->GetTime(ip) > 1e5*/ ) { // Set Max at 10 musec
189  //G4cout << " Apply time correction to event hits of " << (*WCHC)[i]->GetTime(ip) << " ns" << G4endl;
190  first_time = (*WCHC)[i]->GetTime(ip);
191  }
192 
193  time_true = (*WCHC)[i]->GetTime(ip);
194  time_PMT = time_true - first_time; //currently no PMT time smearing applied
195  peSmeared = rn1pe();
196  int parent_id = (*WCHC)[i]->GetParentID(ip);
197 
198  if ( DigiHitMapPMT[tube] == 0) {
199  WCSimWCDigi* Digi = new WCSimWCDigi();
200  Digi->SetLogicalVolume((*WCHC)[0]->GetLogicalVolume());
201  Digi->AddPe(time_PMT);
202  Digi->SetTubeID(tube);
203  Digi->SetPe(ip,peSmeared);
204  Digi->SetTime(ip,time_PMT);
205  Digi->SetPreSmearTime(ip,time_true);
206  Digi->SetParentID(ip,parent_id);
207  DigiHitMapPMT[tube] = DigitsCollection->insert(Digi);
208  }
209  else {
210  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->AddPe(time_PMT);
211  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->SetLogicalVolume((*WCHC)[0]->GetLogicalVolume());
212  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->SetTubeID(tube);
213  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->SetPe(ip,peSmeared);
214  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->SetTime(ip,time_PMT);
215  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->SetPreSmearTime(ip,time_true);
216  (*DigitsCollection)[DigiHitMapPMT[tube]-1]->SetParentID(ip,parent_id);
217  }
218 
219  } // Loop over hits in each PMT
220  }// Loop over PMTs
221 }
222 
223 
void SetPreSmearTime(G4int gate, G4double T)
Definition: WCSimWCDigi.hh:89
void skrn1pe_(double *)
void SetLogicalVolume(G4LogicalVolume *logV)
Definition: WCSimWCDigi.hh:121
static G4double first_time
Definition: WCSimWCPMT.hh:49
void SetTubeID(G4int tube)
Definition: WCSimWCDigi.hh:85
virtual G4double * Getqpe()=0
WCSimPMTObject * GetPMTPointer(G4String CollectionName)
G4THitsCollection< WCSimWCHit > WCSimWCHitsCollection
Definition: WCSimWCHit.hh:169
void SetPe(G4int gate, G4double Q)
Definition: WCSimWCDigi.hh:87
WCSimDetectorConstruction * myDetector
Definition: WCSimWCPMT.hh:43
G4TDigiCollection< WCSimWCDigi > WCSimWCDigitsCollection
Definition: WCSimWCDigi.hh:214
std::map< int, int > DigiHitMapPMT
Definition: WCSimWCPMT.hh:40
WCSimWCPMT(G4String name, WCSimDetectorConstruction *, G4String detectorElement)
Definition: WCSimWCPMT.cc:31
G4String detectorElement
Definition: WCSimWCPMT.hh:44
void Digitize()
Definition: WCSimWCPMT.cc:82
WCSimWCDigitsCollection * DigitsCollection
Definition: WCSimWCPMT.hh:42
void MakePeCorrection(WCSimWCHitsCollection *)
Definition: WCSimWCPMT.cc:135
void AddPe(G4double hitTime)
Definition: WCSimWCDigi.hh:128
void SetTime(G4int gate, G4double T)
Definition: WCSimWCDigi.hh:88
G4double peSmeared
Definition: WCSimWCPMT.hh:37
void SetParentID(G4int gate, G4int parent)
Definition: WCSimWCDigi.hh:90
bool RelativeHitTime
Definition: WCSimWCPMT.hh:47
G4double rn1pe()
Definition: WCSimWCPMT.cc:55