]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliSDManager.cxx
removed old commented lines only
[u/mrichter/AliRoot.git] / AliGeant4 / AliSDManager.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // See the class description in the header file.
5
6 #include "AliSDManager.h"
7 //#include "AliSDMessenger.h"
8 #include "AliSensitiveDetector.h"
9 #include "AliLegoSensitiveDetector.h"
10 #include "AliGlobals.h"
11 #include "AliFiles.h"
12 #include "AliRun.h"
13 #include "AliModule.h"
14
15 #include "TG4GeometryManager.h"
16
17 #include <G3SensVolVector.hh>
18 #include <G4SDManager.hh>
19 #include <G4UImanager.hh>
20 #include <G4LogicalVolume.hh>
21 #include <G4LogicalVolumeStore.hh>
22
23 AliSDManager* AliSDManager::fgInstance = 0;
24
25 AliSDManager* AliSDManager::Instance()
26 {
27 // Returns the singleton instance.
28 // Creates the instance if it does not exist.
29 // ---
30
31   if (!fgInstance) new AliSDManager();
32   
33   return fgInstance;
34 }  
35     
36 AliSDManager::AliSDManager() {
37 //
38   //fMessenger = new AliSDMessenger(this);
39   fgInstance = this;
40 }
41
42 AliSDManager::AliSDManager(const AliSDManager& right) {
43 //
44   AliGlobals::Exception(
45     "Singleton AliSDManager is protected from copying.");
46 }
47
48 AliSDManager::~AliSDManager()
49 {
50   //delete fMessenger;
51 }
52
53 // operators
54
55 AliSDManager& AliSDManager::operator=(const AliSDManager& right)
56 {
57   // check assignement to self
58   if (this == &right) return *this;
59
60   AliGlobals::Exception(
61      "Singleton AliSDManager is protected from assigning.");
62     
63   return *this;  
64 }    
65           
66 // private methods
67
68 void AliSDManager::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const
69
70 // Replaces the existing sensitive detector of the logical volume
71 // with the lego sensitive detector.
72 // ---
73
74   TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
75   G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
76
77   G4String lvName = lv->GetName(); 
78   G4String sdName = "/Alice/lego/" + lvName;
79
80   // cut copy number from sdName
81   pGeometryManager->G4ToG3VolumeName(sdName);
82   
83   // retrieve the standard sensitive detector
84   G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
85
86   // create/retrieve the lego sensitive detector
87   G4VSensitiveDetector* legoVSD = 0; 
88   legoVSD = pSDManager->FindSensitiveDetector(sdName);
89
90   if (!legoVSD) {
91     AliLegoSensitiveDetector* legoSD
92       = new AliLegoSensitiveDetector(sdName, lego, sd); 
93     pSDManager->AddNewDetector(legoSD);
94     // add verbose
95     G4cout << "Lego sensitive detector " << sdName 
96          << ") has been created." << G4endl;
97     legoVSD = legoSD;  
98   }       
99   lv->SetSensitiveDetector(legoVSD);         
100 }
101
102 void AliSDManager::UnsetLegoSD(G4LogicalVolume* lv) const
103
104 // Replace the lego sensitive detector of the logical volume
105 // with the standard sensitive detector.
106 // ---
107
108   G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
109
110   // get the lego sensitive detector
111   G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
112   AliLegoSensitiveDetector* legoSD = 0; 
113   if (sd) {
114     // check type
115     legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd);
116     if (!legoSD) {
117       G4String text = "AliSDManager::UnsetLego: \n";
118       text = text + "    Wrong sensitive detector type.";
119       AliGlobals::Exception(text);
120     }   
121   }
122  
123   // get the standard sensitive detector
124   G4VSensitiveDetector* standardSD = legoSD->GetStandardSD();
125
126   // set the standard sensitive detector
127   lv->SetSensitiveDetector(standardSD);      
128 }
129
130
131 // public methods
132
133 void AliSDManager::CreateSD(G4LogicalVolume* lv, AliModule* module) const
134
135 // Creates/retrieves a sensitive detector for the logical volume.
136 // ---
137
138   TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
139   G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
140
141   G4String lvName = lv->GetName(); 
142   
143   G4String moduleName = module->GetName();
144   G4String sdName = "/Alice/" + moduleName + "/" + lvName;
145
146   // cut copy number from sdName
147   pGeometryManager->G4ToG3VolumeName(sdName);
148   
149   // create/retrieve the sensitive detector
150   G4VSensitiveDetector* sd = 0; 
151   sd = pSDManager->FindSensitiveDetector(sdName);
152   if (!sd) {
153     AliSensitiveDetector* asd 
154       = new AliSensitiveDetector(sdName, module);       
155     pSDManager->AddNewDetector(asd);
156     // add verbose
157     G4cout << "Sensitive detector " << sdName << "(" 
158            << asd->GetID() << ") has been created." << G4endl;
159     sd = asd;  
160   }     
161   lv->SetSensitiveDetector(sd);      
162 }
163
164 AliModule* AliSDManager::FindAliModule(G4LogicalVolume* lv) const
165 {
166 // Finds the module containing specified logical volume.
167 // ---
168
169   // geometry manager
170   TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
171
172   // get g3 volume name
173   G4String g3Name = lv->GetName();
174   pGeometryManager->G4ToG3VolumeName(g3Name);
175   
176   // get module name from the map
177   G4String moduleName = pGeometryManager->GetMapSecond(g3Name);
178   
179   // find module from gAlice
180   AliModule* module = gAlice->GetModule(moduleName);
181   if (!module) {
182     G4String text = "AliSDManager::FindAliModule:\n";
183     text = text + "    AliModule " + moduleName;
184     text = text + " (mapped from logical volume " + lv->GetName() + ")\n";
185     text = text + "    has not been found in gAlice.";
186     AliGlobals::Exception(text);
187   }  
188    
189   return module;
190 }  
191
192 void AliSDManager::SetLego(AliLego* lego) const 
193
194 // Replaces the existing sensitive detectors 
195 // with lego sensitive detectors.
196 // ---
197
198   if (!lego) {
199     G4String text = "AliSDManager::SetLego: \n";
200     text = text + "    No AliLego is defined.";
201     AliGlobals::Warning(text);
202     return;
203   }  
204
205   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
206   G4int nofLV = pLVStore->entries();
207   
208   for (G4int i=0; i<nofLV; i++) {
209     G4LogicalVolume* lv = (*pLVStore)[i];
210     CreateLegoSD(lv, lego);
211   }
212 }
213
214 void AliSDManager::UnsetLego() const
215 {
216 // Replace the lego sensitive detectors 
217 // back with standard sensitive detectors.
218 // ---
219
220   G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
221   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
222   G4int nofLV = pLVStore->entries();
223   
224   // set back standard sensitive detectors
225   for (G4int i=0; i<nofLV; i++) {
226     G4LogicalVolume* lv = (*pLVStore)[i];
227     UnsetLegoSD(lv);
228   }  
229
230   // The lego sensitive detectors are not deleted here
231   // as there is no way how to unregister them
232   // from G4SDManager
233 }