1 #include "ERN15B11Detector.h" 4 #include <TClonesArray.h> 5 #include <TGeoMatrix.h> 6 #include <TVirtualMC.h> 7 #include <TGeoManager.h> 13 #include <FairRootManager.h> 15 #include <FairVolume.h> 18 #include "cppTokenizer.h" 25 Int_t ERN15B11Detector::mCurNodeUID = -1;
27 ERN15B11Detector::ERN15B11Detector() :
30 LOG(DEBUG) <<
"ERN15B11Detector::ERN15B11Detector()" << FairLogger::endl;
33 ERN15B11Detector::ERN15B11Detector(
const char* Name, Bool_t Active, Int_t DetId) :
34 FairDetector(Name, Active, DetId)
36 LOG(DEBUG) <<
"ERN15B11Detector::ERN15B11Detector(" << Name <<
")" << FairLogger::endl;
39 ERN15B11Detector::~ERN15B11Detector()
43 void ERN15B11Detector::ConstructGeometry()
45 TString fileName = GetGeometryFileName();
46 if(fileName.EndsWith(
".root")) {
47 LOG(INFO) <<
"Constructing geometry from ROOT file '" << fileName.Data() <<
"'" << FairLogger::endl;
48 this->ConstructRootGeometry();
50 else if (fileName.EndsWith(
".gdml")) {
51 LOG(INFO) <<
"Constructing geometry from GDML file '" << fileName.Data() <<
"'" << FairLogger::endl;
52 TGeoRotation* zeroRotation =
new TGeoRotation(
"zeroRotation", 0., 0., 0.);
53 this->ConstructGDMLGeometry(
new TGeoCombiTrans(0., 0., 0., zeroRotation));
56 LOG(FATAL) <<
"Unknown geometry file format." << FairLogger::endl;
60 Bool_t ERN15B11Detector::CheckIfSensitive(std::string name)
62 LOG(DEBUG) <<
"ERN15B11Detector::CheckIfSensitive(" << name <<
")" << FairLogger::endl;
73 if (name ==
"vDetGasPart") {
76 if (name ==
"vSemi") {
83 Bool_t ERN15B11Detector::ProcessHits(FairVolume* v)
85 const char* curNodePath = gMC->CurrentVolPath();
86 Int_t curNodeId = this->GetCurNodeSig(curNodePath);
89 LOG(DEBUG2) <<
"ERN15B11Detector::ProcessHits(" << v->GetName() <<
") " 90 <<
"particle charge: " << gMC->TrackCharge() <<
" " 91 << curNodePath <<
": " << mCurNodeUID
95 std::map<Int_t, TClonesArray*>::iterator iter = mOutputPoints.find(mCurNodeUID);
97 TClonesArray* v_outputCollection = NULL;
99 if (iter != mOutputPoints.end()) {
101 v_outputCollection = iter->second;
102 LOG(DEBUG2) <<
"Collection found." << FairLogger::endl;
105 LOG(FATAL) <<
"Collection not found." << FairLogger::endl;
109 fELoss += gMC->Edep();
112 if (gMC->IsTrackEntering()) {
116 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
117 FinishNewPoint(v_outputCollection);
123 void ERN15B11Detector::EndOfEvent()
125 LOG(DEBUG) <<
"ERN15B11Detector::EndOfEvent" << FairLogger::endl;
129 void ERN15B11Detector::Register()
131 LOG(DEBUG) <<
"ERN15B11Detector::Register" << FairLogger::endl;
133 FairRootManager* ioman = FairRootManager::Instance();
135 LOG(FATAL) <<
"IO manager is not set" << FairLogger::endl;
138 TGeoIterator next(gGeoManager->GetTopVolume());
141 while ((node=next())) {
143 next.GetPath(curPath);
145 Bool_t curSig = this->GetCurNodeSig(curPath);
147 LOG(DEBUG) << curPath <<
": " << mCurNodeUID << FairLogger::endl;
150 std::map<Int_t, TClonesArray*>::iterator iter = mOutputPoints.find(mCurNodeUID);
152 if (iter != mOutputPoints.end()) {
154 TClonesArray* v_collection = iter->second;
155 LOG(DEBUG) <<
"Collection found." << FairLogger::endl;
161 TClonesArray* v_newCollection =
new TClonesArray(
"ERPoint");
162 mOutputPoints.insert(std::pair<Int_t, TClonesArray*>(mCurNodeUID, v_newCollection));
166 if ((mCurNodeSig.iSemi == -1) && (mCurNodeSig.iDetGasPart != -1)) {
168 v_name.Form(
"Gas_Layer_%d_Det_%d", mCurNodeSig.iLayer, mCurNodeSig.iDetContainer);
169 }
else if ((mCurNodeSig.iSemi != -1) && (mCurNodeSig.iDetGasPart == -1)) {
171 v_name.Form(
"Semi_Layer_%d_Det_%d", mCurNodeSig.iLayer, mCurNodeSig.iDetContainer);
173 ioman->Register(v_name + TString(
"_Point"), v_name, v_newCollection, kTRUE);
175 LOG(DEBUG) <<
"Collection not found - create it: " << v_name << FairLogger::endl;
182 TClonesArray* ERN15B11Detector::GetCollection(Int_t iColl)
const 184 LOG(DEBUG) <<
"ERN15B11Detector::GetCollection" << FairLogger::endl;
199 void ERN15B11Detector::Reset()
201 LOG(DEBUG) <<
"ERN15B11Detector::Reset" << FairLogger::endl;
203 std::map<Int_t, TClonesArray*>::iterator iter;
205 for (iter = mOutputPoints.begin(); iter != mOutputPoints.end(); ++iter) {
206 TClonesArray* curCollection = iter->second;
207 curCollection->Clear();
214 mCurNodeSig.iLayer = -1;
215 mCurNodeSig.iDetContainer = -1;
216 mCurNodeSig.iDetGasPart = -1;
217 mCurNodeSig.iSemi = -1;
219 std::vector<std::string> mVolumesList;
222 mVolumesList.push_back(std::string(
"vOneLayer_"));
223 mVolumesList.push_back(std::string(
"vDetContainer_"));
224 mVolumesList.push_back(std::string(
"vDetGasPart_"));
225 mVolumesList.push_back(std::string(
"vSemi_"));
227 std::string fullPath(nodePath);
228 std::string delimiter(
"/");
229 std::vector<std::string> tokens = tokenize(fullPath, delimiter);
231 std::vector<std::string>::const_iterator iter;
232 for (iter = tokens.begin(); iter != tokens.end(); ++iter) {
236 UChar_t iCounter = 0;
237 std::vector<std::string>::const_iterator iter2;
238 for (iter2 = mVolumesList.begin(); iter2 != mVolumesList.end(); ++iter2) {
240 size_t curStrLen = (*iter).size();
241 size_t curSearchedStrLen = (*iter2).size();
246 if ((*iter).compare(0, curSearchedStrLen, (*iter2)) == 0) {
247 Short_t res = std::stoi((*iter).substr(curSearchedStrLen));
251 case 0: mCurNodeSig.iLayer = res;
break;
252 case 1: mCurNodeSig.iDetContainer = res;
break;
253 case 2: mCurNodeSig.iDetGasPart = res;
break;
254 case 3: mCurNodeSig.iSemi = res;
break;
266 LOG(DEBUG3) << nodePath
268 <<
" iLayer=" << mCurNodeSig.iLayer
269 <<
" iDetContainer=" << mCurNodeSig.iDetContainer
270 <<
" iDetGasPart=" << mCurNodeSig.iDetGasPart
271 <<
" iSemi=" << mCurNodeSig.iSemi
274 if ((mCurNodeSig.iDetContainer != -1) && (mCurNodeSig.iLayer != -1))
276 if ((mCurNodeSig.iSemi == -1) && (mCurNodeSig.iDetGasPart != -1)) {
278 mCurNodeUID = mCurNodeSig.iLayer * 100 + mCurNodeSig.iDetContainer;
281 }
else if ((mCurNodeSig.iSemi != -1) && (mCurNodeSig.iDetGasPart == -1)) {
283 mCurNodeUID = 10000 + mCurNodeSig.iLayer * 100 + mCurNodeSig.iDetContainer;
295 void ERN15B11Detector::StartNewPoint(
void)
298 fEventID = gMC->CurrentEvent();
299 gMC->TrackPosition(fPosIn);
300 gMC->TrackMomentum(fMomIn);
301 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
302 fTimeIn = gMC->TrackTime() * 1.0e09;
303 fTrackLength = gMC->TrackLength();
304 fMot0TrackID = gMC->GetStack()->GetCurrentTrack()->GetMother(0);
305 fMass = gMC->ParticleMass(gMC->TrackPid());
306 Int_t curVolId, corOffVolId;
307 curVolId = gMC->CurrentVolID(fVolNb);
309 gMC->GetTransformation(gMC->CurrentVolPath(), matrix);
310 Double_t globalPos[3], localPos[3];
311 fPosIn.Vect().GetXYZ(globalPos);
312 matrix.MasterToLocal(globalPos, localPos);
313 fPosInLocal.SetXYZ(localPos[0], localPos[1], localPos[2]);
316 void ERN15B11Detector::FinishNewPoint(TClonesArray* p_collection)
318 gMC->TrackPosition(fPosOut);
319 gMC->TrackMomentum(fMomOut);
320 fTimeOut = gMC->TrackTime() * 1.0e09;
323 AddPoint(p_collection);
327 ERPoint* ERN15B11Detector::AddPoint(TClonesArray* p_collection)
329 if (p_collection == NULL) {
330 LOG(WARNING) <<
"Trying to add an output point into a NULL collection." << FairLogger::endl;
334 TClonesArray& clref = *p_collection;
335 Int_t size = clref.GetEntriesFast();
336 return new(clref[size])
ERPoint(fEventID, fTrackID, fMot0TrackID, fVolNb,
337 fMass, fPosIn.Vect(),fPosInLocal,fPosOut.Vect(),fMomIn.Vect(),fMomOut.Vect(),fTimeIn,
338 fTimeOut, fTrackLength, fELoss, 0., gMC->TrackPid(), gMC->TrackCharge());
Bool_t GetCurNodeSig(const char *nodePath) const
The data class for storing pieces of charged tracks in sensitive volumes in NeuRad.