CbmRoot
Loading...
Searching...
No Matches
CbmMuch.cxx
Go to the documentation of this file.
1/* Copyright (C) 2008-2020 St. Petersburg Polytechnic University, St. Petersburg
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Mikhail Ryzhinskiy [committer], Vikas Singhal, Florian Uhlig */
4
5//----------------------------------------------------------------------------------------
6//-------------- CbmMuch -----------
7//--------------- Modified 18/10/2017 by Omveer Singh -----------
8//----------------------------------------------------------------------------------------
9
10
11#include "CbmMuch.h"
12
13#include "CbmGeoMuch.h"
14#include "CbmGeoMuchPar.h"
15#include "CbmGeometryUtils.h"
16#include "CbmMuchAddress.h"
17#include "CbmMuchGeoScheme.h"
18#include "CbmMuchLayer.h"
19#include "CbmMuchLayerSide.h"
20#include "CbmMuchModule.h"
22#include "CbmMuchPoint.h"
23#include "CbmMuchStation.h"
24#include "CbmStack.h"
25
26#include "FairGeoInterface.h"
27#include "FairGeoLoader.h"
28#include "FairGeoMedia.h"
29#include "FairGeoMedium.h"
30#include "FairGeoNode.h"
31#include "FairGeoRootBuilder.h"
32#include "FairRootManager.h"
33#include "FairRun.h"
34#include "FairRuntimeDb.h"
35#include "FairVolume.h"
36
37#include "TClonesArray.h"
38#include "TGeoArb8.h"
39#include "TGeoBBox.h"
40#include "TGeoBoolNode.h"
41#include "TGeoCompositeShape.h"
42#include "TGeoCone.h"
43#include "TGeoMCGeometry.h"
44#include "TGeoManager.h"
45#include "TGeoMatrix.h"
46#include "TGeoTube.h"
47#include "TGeoVolume.h"
48#include "TKey.h"
49#include "TObjArray.h"
50#include "TParticle.h"
51#include "TVirtualMC.h"
52#include <TFile.h>
53
54#include <cassert>
55#include <fstream>
56#include <iostream>
57
58using std::cout;
59using std::endl;
60
62
63 // ----- Default constructor -------------------------------------------
65 : FairDetector()
66 , fTrackID(-1)
67 , fVolumeID(-1)
68 , fFlagID(0)
69 , fPosIn()
70 , fPosOut()
71 , fMomIn()
72 , fMomOut()
73 , fTime(0.)
74 , fLength(0.)
75 , fELoss(0.)
76 , fPosIndex(0)
77 , fMuchCollection(new TClonesArray("CbmMuchPoint"))
78 , kGeoSaved(kFALSE)
79 , flGeoPar(new TList())
80 , fPar(NULL)
81 , fVolumeName("")
82 , fCombiTrans()
83{
84 ResetParameters();
85 flGeoPar->SetName(GetName());
86 fVerboseLevel = 1;
87}
88// -------------------------------------------------------------------------
89
90
91// ----- Standard constructor ------------------------------------------
92CbmMuch::CbmMuch(const char* name, Bool_t active)
93 : FairDetector(name, active)
94 , fTrackID(-1)
95 , fVolumeID(-1)
96 , fFlagID(0)
97 , fPosIn()
98 , fPosOut()
99 , fMomIn()
100 , fMomOut()
101 , fTime(0.)
102 , fLength(0.)
103 , fELoss(0.)
104 , fPosIndex(0)
105 , fMuchCollection(new TClonesArray("CbmMuchPoint"))
106 , kGeoSaved(kFALSE)
107 , flGeoPar(new TList())
108 , fPar(NULL)
109 , fVolumeName("")
110 , fCombiTrans()
111{
112
114 flGeoPar->SetName(GetName());
115 fVerboseLevel = 1;
116}
117
118
119// ----- Destructor ----------------------------------------------------
121{
122
123 if (flGeoPar) delete flGeoPar;
124 if (fMuchCollection) {
125 fMuchCollection->Delete();
126 delete fMuchCollection;
127 }
128}
129
130
131// ----- Public method ProcessHits --------------------------------------
132
133
134Bool_t CbmMuch::ProcessHits(FairVolume* vol)
135{
136 // cout<<" called process Hit****************** "<<endl;
137 if (gMC->IsTrackEntering()) {
138 fELoss = 0.;
139 fTime = gMC->TrackTime() * 1.0e09;
140 fLength = gMC->TrackLength();
141 gMC->TrackPosition(fPosIn);
142 gMC->TrackMomentum(fMomIn);
143 }
144
145 // Sum energy loss for all steps in the active volume
146 fELoss += gMC->Edep();
147
148 // Set additional parameters at exit of active volume. Create CbmMuchPoint.
149 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
150 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
151 fVolumeID = vol->getMCid();
152 Int_t fDetectorId = GetDetId(vol);
153 // cout<<" check det ID 2 "<<fDetectorId<<endl;
154 if (fVerboseLevel > 2) {
155 printf(" TrackId: %i", fTrackID);
156 printf(" System: %i", CbmMuchAddress::GetSystemIndex(fDetectorId));
157 printf(" Station: %i", CbmMuchAddress::GetStationIndex(fDetectorId));
158 printf(" Layer: %i", CbmMuchAddress::GetLayerIndex(fDetectorId));
159 printf(" Side: %i", CbmMuchAddress::GetLayerSideIndex(fDetectorId));
160 printf(" Module: %i", CbmMuchAddress::GetModuleIndex(fDetectorId));
161 printf(" Vol %i \n", fVolumeID);
162 }
163 gMC->TrackPosition(fPosOut);
164 gMC->TrackMomentum(fMomOut);
165 /*
166 Int_t iStation = CbmMuchAddress::GetStationIndex(fDetectorId);
167 assert(iStation >= 0 && iStation < fPar->GetNStations());
168 CbmMuchStation* station = (CbmMuchStation*) fPar->GetStations()->At(iStation);
169 //cout<<" track # "<<fTrackID<<" Rmin "<<station->GetRmin()<<" Rmax "<<station->GetRmax()<<" in perp "<<fPosIn.Perp()<<" out perp "<<fPosOut.Perp()<<" eloss "<<fELoss<<endl;
170 if (fPosIn.Perp() > station->GetRmax()) { return kFALSE; }
171 if (fPosOut.Perp() > station->GetRmax()) { return kFALSE; }
172 if (fPosIn.Perp() < station->GetRmin()) { return kFALSE; }
173 if (fPosOut.Perp() < station->GetRmin()) { return kFALSE; }
174 */ //commented by SR
175
176 if (fELoss == 0.) return kFALSE;
177 AddHit(fTrackID, fDetectorId, TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()),
178 TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), TVector3(fMomIn.Px(), fMomIn.Py(), fMomIn.Pz()),
179 TVector3(fMomOut.Px(), fMomOut.Py(), fMomOut.Pz()), fTime, fLength, fELoss);
180
181 //if (fPosOut.Z()>250) printf("%f\n",fPosOut.Z());
182
183 // Increment number of MuchPoints for this track
184 CbmStack* stack = (CbmStack*) gMC->GetStack();
186
188 }
189 return kTRUE;
190}
191
192
193//-------------------------------------------------------------------------
194
195Int_t CbmMuch::GetDetId(FairVolume* vol)
196{
197 TString name = vol->GetName();
198 Char_t cStationNr[3] = {name[11], name[12], ' '};
199 Int_t iStation = atoi(cStationNr) - 1;
200 Int_t iLayer = TString(name[18]).Atoi() - 1;
201 Int_t iSide = (name[19] == 'b') ? 1 : 0;
202 Char_t cModuleNr[4] = {name[26], name[27], name[28], ' '};
203 Int_t iModule = atoi(cModuleNr) - 1;
204 if (iSide != 1 && iSide != 0) printf("side = %i", iSide);
205 Int_t detectorId = CbmMuchAddress::GetAddress(iStation, iLayer, iSide, iModule);
206 assert(CbmMuchAddress::GetStationIndex(detectorId) == iStation);
207 assert(CbmMuchAddress::GetLayerIndex(detectorId) == iLayer);
208 assert(CbmMuchAddress::GetLayerSideIndex(detectorId) == iSide);
209 assert(CbmMuchAddress::GetModuleIndex(detectorId) == iModule);
210 assert(detectorId > 0);
211
212 return detectorId;
213}
214
215// -------------------------------------------------------------------------
217
218
219// -------------------------------------------------------------------------
221{
222 if (fVerboseLevel) Print("");
223 fMuchCollection->Delete();
225}
226
227// -------------------------------------------------------------------------
228void CbmMuch::Register() { FairRootManager::Instance()->Register("MuchPoint", GetName(), fMuchCollection, kTRUE); }
229
230// -------------------------------------------------------------------------
231TClonesArray* CbmMuch::GetCollection(Int_t iColl) const
232{
233 if (iColl == 0) return fMuchCollection;
234 else
235 return NULL;
236}
237// -------------------------------------------------------------------------
238
239
240// -------------------------------------------------------------------------
241void CbmMuch::Print(Option_t*) const
242{
243 Int_t nHits = fMuchCollection->GetEntriesFast();
244 LOG(info) << fName << ": " << nHits << " points registered in this event.";
245}
246
247// -------------------------------------------------------------------------
249{
250 fMuchCollection->Delete();
252}
253
254// -------------------------------------------------------------------------
255void CbmMuch::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset)
256{
257 Int_t nEntries = cl1->GetEntriesFast();
258 LOG(info) << fName << ": " << nEntries << " entries to add.";
259 TClonesArray& clref = *cl2;
260 CbmMuchPoint* oldpoint = NULL;
261 for (Int_t i = 0; i < nEntries; i++) {
262 oldpoint = (CbmMuchPoint*) cl1->At(i);
263 Int_t index = oldpoint->GetTrackID() + offset;
264 oldpoint->SetTrackID(index);
265 new (clref[fPosIndex]) CbmMuchPoint(*oldpoint);
266 fPosIndex++;
267 }
268 LOG(info) << fName << ": " << cl2->GetEntriesFast() << " merged entries.";
269}
270// -------------------------------------------------------------------------
271
272
273// ----- Private method AddHit --------------------------------------------
274CbmMuchPoint* CbmMuch::AddHit(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn,
275 TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
276{
277
278 TClonesArray& clref = *fMuchCollection;
279 Int_t size = clref.GetEntriesFast();
280 if (fVerboseLevel > 1)
281 LOG(info) << fName << ": Adding Point at (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z()
282 << ") cm, detector " << detID << ", track " << trackID << ", energy loss " << eLoss * 1e06 << " keV";
283
284 return new (clref[size]) CbmMuchPoint(trackID, detID, posIn, posOut, momIn, momOut, time, length, eLoss);
285}
286
287// ----- ConstructGeometry -----------------------------------------------
289{
290
291 TString fileName = GetGeometryFileName();
292
293 // --- Only ROOT geometries are supported
294 if (!fileName.EndsWith(".root")) {
295 LOG(fatal) << GetName() << ": Geometry format of file " << fileName.Data() << " not supported.";
296 }
297
298 if (fileName.Contains("mcbm")) {
299
300 fFlagID = 1;
301 LOG(info) << "mcbm geometry found ";
302 }
304}
305// -------------------------------------------------------------------------
306
307
309{
310 FairRun* fRun = FairRun::Instance();
311 if (!fRun) {
312 Fatal("CreateGeometry", "No FairRun found");
313 return;
314 }
315 FairRuntimeDb* rtdb = FairRuntimeDb::instance();
316 fPar = (CbmGeoMuchPar*) (rtdb->getContainer("CbmGeoMuchPar"));
317 TObjArray* stations = fPar->GetStations();
318
319 //-------------------------------------------------------
320
322
323 fGeoScheme->Init(stations, fFlagID);
324
325 TGeoMatrix* tempMatrix {nullptr};
326 if (Cbm::GeometryUtils::IsNewGeometryFile(fgeoName, fVolumeName, &tempMatrix)) {
327 LOG(info) << "Importing MUCH geometry from ROOT file " << fgeoName.Data();
329 }
330 else {
331 LOG(info) << "Constructing MUCH geometry from ROOT file " << fgeoName.Data();
332 FairModule::ConstructRootGeometry();
333 }
334
335
336 TObjArray* fSensNodes = fPar->GetGeoSensitiveNodes();
337 TObjArray* fPassNodes = fPar->GetGeoPassiveNodes();
338 TGeoNode* ncave = gGeoManager->GetTopNode();
339
340 // fGeoScheme->ExtractGeoParameter(ncave, fVolumeName.Data()); //commented by SR
341
342 TString objName = fVolumeName + "_0";
343 TGeoNode* nmuch = (TGeoNode*) ncave->GetNodes()->FindObject(objName);
344 fPassNodes->Add(nmuch);
345
346
347 TObjArray* nodes = nmuch->GetNodes();
348
349 for (Int_t i = 0; i < nodes->GetEntriesFast(); i++) {
350 TGeoNode* node = (TGeoNode*) nodes->At(i);
351 TString nodeName = node->GetName();
352
353
354 TObjArray* nodes1 = node->GetNodes();
355
356 for (Int_t j = 0; j < nodes1->GetEntriesFast(); j++) {
357 TGeoNode* node1 = (TGeoNode*) nodes1->At(j);
358 TString node1Name = node1->GetName();
359
360 if (node1Name.Contains("absblock")) fPassNodes->Add(node);
361 if (node1Name.Contains("muchstation")) {
362
363 TObjArray* layers = node1->GetNodes();
364 for (Int_t l = 0; l < layers->GetEntriesFast(); l++) {
365 TGeoNode* layer = (TGeoNode*) layers->At(l);
366
367 if (!TString(layer->GetName()).Contains("layer")) continue;
368 TObjArray* layerNodes = layer->GetNodes();
369 for (Int_t m = 0; m < layerNodes->GetEntriesFast(); m++) {
370 TGeoNode* layerNode = (TGeoNode*) layerNodes->At(m);
371 TString layerNodeName = layerNode->GetName();
372
373 if (layerNodeName.Contains("active")) fSensNodes->Add(layerNode);
374
375 if (layerNodeName.Contains("support")) fPassNodes->Add(layerNode);
376
377 if (layerNodeName.Contains("cool")) fPassNodes->Add(layerNode);
378 }
379 }
380 }
381 }
382 }
383
384 fPar->setChanged();
385 fPar->setInputVersion(fRun->GetRunId(), 1);
386}
387
388
389// ----- CheckIfSensitive -------------------------------------------------
390Bool_t CbmMuch::IsSensitive(const std::string& name)
391{
392 TString tsname = name;
393
394
395 if (tsname.Contains("active")) {
396 LOG(debug1) << "CbmMuch::CheckIfSensitive: Register active volume: " << tsname;
397 return kTRUE;
398 }
399 return kFALSE;
400}
401
402Bool_t CbmMuch::CheckIfSensitive(std::string name) { return IsSensitive(name); }
@ kMuch
Muon detection system.
ClassImp(CbmMuch) CbmMuch
Definition CbmMuch.cxx:61
static constexpr size_t size()
Definition KfSimdPseudo.h:2
TObjArray * GetGeoPassiveNodes()
TObjArray * GetStations()
TObjArray * GetGeoSensitiveNodes()
static int32_t GetModuleIndex(int32_t address)
static int32_t GetLayerIndex(int32_t address)
static int32_t GetLayerSideIndex(int32_t address)
static int32_t GetSystemIndex(int32_t address)
static uint32_t GetAddress(int32_t station=0, int32_t layer=0, int32_t side=0, int32_t module=0, int32_t sector=0, int32_t channel=0)
static int32_t GetStationIndex(int32_t address)
static CbmMuchGeoScheme * Instance()
void Init(TObjArray *stations, Int_t flag)
virtual void Register()
Definition CbmMuch.cxx:228
TString fVolumeName
parameter container
Definition CbmMuch.h:134
Int_t fVolumeID
track index
Definition CbmMuch.h:121
virtual void ConstructRootGeometry(TGeoMatrix *shift=NULL)
Definition CbmMuch.cxx:308
TList * flGeoPar
Definition CbmMuch.h:132
virtual void Reset()
Definition CbmMuch.cxx:248
virtual ~CbmMuch()
Definition CbmMuch.cxx:120
virtual Bool_t IsSensitive(const std::string &name)
Definition CbmMuch.cxx:390
Int_t fPosIndex
energy loss
Definition CbmMuch.h:129
CbmMuchPoint * AddHit(Int_t trackID, Int_t detID, TVector3 posIn, TVector3 posOut, TVector3 momIn, TVector3 momOut, Double_t time, Double_t length, Double_t eLoss)
Definition CbmMuch.cxx:274
virtual void BeginEvent()
Definition CbmMuch.cxx:216
Int_t GetDetId(FairVolume *vol)
Definition CbmMuch.cxx:195
Int_t fFlagID
volume id
Definition CbmMuch.h:122
TLorentzVector fMomIn
position
Definition CbmMuch.h:124
Double32_t fELoss
length
Definition CbmMuch.h:127
TClonesArray * fMuchCollection
Definition CbmMuch.h:130
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition CbmMuch.cxx:231
virtual void Print(Option_t *) const
Definition CbmMuch.cxx:241
virtual void EndOfEvent()
Definition CbmMuch.cxx:220
void ResetParameters()
Definition CbmMuch.h:158
TLorentzVector fPosIn
Definition CbmMuch.h:123
Int_t fTrackID
Definition CbmMuch.h:120
Bool_t CheckIfSensitive(std::string name)
Definition CbmMuch.cxx:402
TLorentzVector fPosOut
Definition CbmMuch.h:123
Double32_t fLength
time
Definition CbmMuch.h:126
virtual void ConstructGeometry()
Definition CbmMuch.cxx:288
CbmGeoMuchPar * fPar
Definition CbmMuch.h:133
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition CbmMuch.cxx:134
TLorentzVector fMomOut
Definition CbmMuch.h:124
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition CbmMuch.cxx:255
Double32_t fTime
momentum
Definition CbmMuch.h:125
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331
Bool_t IsNewGeometryFile(TString &filename)
void ImportRootGeometry(TString &filename, FairModule *mod, TGeoMatrix *mat)