BmnRoot
Loading...
Searching...
No Matches
BmnZdc.FWall_orig.cxx
Go to the documentation of this file.
1
2/*************************************************************************************
3 *
4 * Class BmnZdc
5 *
6 * Adopted for BMN by: Elena Litvinenko (EL)
7 * e-mail: litvin@nf.jinr.ru
8 * Version: 06-11-2015
9 * Last update: 22-Feb-2012 (EL)
10 * Last update: 05-May-2016 (MG)
11 *
12 ************************************************************************************/
13
14#include <iostream>
15
16#include "TClonesArray.h"
17#include "TGeoMCGeometry.h"
18#include "TGeoManager.h"
19#include "TLorentzVector.h"
20#include "TParticle.h"
21#include "TVirtualMC.h"
22#include "TGeoArb8.h"
23
24#include "FairGeoInterface.h"
25#include "FairGeoLoader.h"
26#include "FairGeoNode.h"
27#include "BmnZdcGeo.h"
28#include "FairGeoRootBuilder.h"
29#include "CbmStack.h"
30#include "BmnZdc.h"
31#include "BmnZdcPoint.h"
32
33#include "FairRootManager.h"
34#include "FairVolume.h"
35// add on for debug
36//#include "FairGeoG3Builder.h"
37#include "FairRuntimeDb.h"
38#include "TObjArray.h"
39#include "FairRun.h"
40
41#include "TParticlePDG.h"
42
43// ----- Default constructor -------------------------------------------
45 fZdcCollection = new TClonesArray("BmnZdcPoint");
46 volDetector = 0;
47 fPosIndex = 0;
48 // fpreflag = 0;
49 //fpostflag = 0;
50 fEventID=-1;
51 fVerboseLevel = 1;
52
53}
54// -------------------------------------------------------------------------
55
56// ----- Standard constructor ------------------------------------------
57BmnZdc::BmnZdc(const char* name, Bool_t active)
58 : FairDetector(name, active) {
59 fZdcCollection = new TClonesArray("BmnZdcPoint");
60 fPosIndex = 0;
61 volDetector = 0;
62 //fpreflag = 0;
63 //fpostflag = 0;
64 fEventID=-1;
65 fVerboseLevel = 1;
66}
67// -------------------------------------------------------------------------
68
69
70
71// ----- Destructor ----------------------------------------------------
73 if (fZdcCollection) {
74 fZdcCollection->Delete();
75 delete fZdcCollection;
76 }
77
78}
79// -------------------------------------------------------------------------
80
81
82
83// ----- Public method Intialize ---------------------------------------
84void BmnZdc::Initialize() {
85 // Init function
86
87 FairDetector::Initialize();
88 FairRun* sim = FairRun::Instance();
89 FairRuntimeDb* rtdb=sim->GetRuntimeDb();
90}
91// -------------------------------------------------------------------------
93 // Begin of the event
94
95}
96
97
98
99// ----- Public method ProcessHits --------------------------------------
100Bool_t BmnZdc::ProcessHits(FairVolume* vol) {
101
102 // if (TMath::Abs(gMC->TrackCharge()) <= 0) return kFALSE;
103
104 Int_t ivol = vol->getMCid();
105 TLorentzVector tPos1, tMom1;
106
107 //#define EDEBUG
108#ifdef EDEBUG
109 static Int_t lEDEBUGcounter=0;
110 if (lEDEBUGcounter<1)
111 std::cout << "EDEBUG-- BmnZdc::ProcessHits: entered" << gMC->CurrentVolPath() << endl;
112#endif
113
114 if (gMC->IsTrackEntering()) {
115
116 ResetParameters();
117 fELoss = 0.;
118#ifdef EDEBUG
119 gMC->TrackPosition(tPos1);
120 gMC->TrackMomentum(tMom1);
121#endif
122 }
123
124 Double_t eLoss = gMC->Edep();
125 if (eLoss != 0.)
126 fELoss += eLoss;
127
128 if ( gMC->IsTrackExiting() ||
129 gMC->IsTrackStop() ||
130 gMC->IsTrackDisappeared() ) {
131
132#ifndef EDEBUG
133 if (fELoss == 0. ) return kFALSE;
134#else
135 if ((fELoss == 0. ) &&
136 (!((gMC->GetStack()->GetCurrentTrack()->GetPdgCode()==2112)&&(gMC->GetStack()->GetCurrentTrack()->GetMother(0)==-1)))
137) return kFALSE;
138#endif
139
140 TParticle* part = gMC->GetStack()->GetCurrentTrack();
141 Double_t charge = part->GetPDG()->Charge() / 3. ;
142
143 // Create BmnZdcPoint
144 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
145 Double_t time = gMC->TrackTime() * 1.0e09;
146 Double_t length = gMC->TrackLength();
147 TLorentzVector tPos, tMom;
148 gMC->TrackPosition(tPos);
149 gMC->TrackMomentum(tMom);
150
151 /*
152 //old geom
153 Int_t copyNo;
154 Int_t ivol1 = gMC->CurrentVolID(copyNo);
155 // ivol1 = vol->getVolumeId();
156 Int_t iCell, iCell2 ;
157 gMC->CurrentVolOffID(1, iCell);
158 gMC->CurrentVolOffID(2, iCell2);
159 */
160
161 //new geom
162 Int_t copyNo;
163 Int_t copyNo_slice;
164 Int_t ivol1 = gMC->CurrentVolID(copyNo_slice);
165 // ivol1 = vol->getVolumeId();
166 Int_t iCell, iCell2 ;
167 gMC->CurrentVolOffID(1, copyNo);
168
169
170#ifdef EDEBUG
171 static Bool_t already=0;
172 if (lEDEBUGcounter<200) {
173 std::cout << "EDEBUG-- BmnZdc::ProcessHits: TrackID:" << fTrackID <<
174 // " ELoss: " << fELoss <<
175 // " particle: " << (part->GetName()) <<
176 " " << gMC->CurrentVolPath() << " " << tPos.X()<< " " << tPos.Y() << " " << tPos.Z() << " " << part->GetPDG()->PdgCode()<<
177 // " " << (gMC->GetStack()->GetCurrentTrack()->GetMother(1)) <<
178 // " " << ivol << "=="<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
179 " " << ivol << " " << vol->getRealName() << " " <<
180 " " << gMC->CurrentVolOffID(1,iCell) << " " << gMC->CurrentVolOffName(1) <<
181 " " << iCell << " " << iCell2 << " "<< gMC->CurrentVolOffName(2) <<
182 " " << vol->getModId()<< " " <<
183 // " " << gMC->CurrentVolOffName(2) << " " << gMC->CurrentVolOffName(1) << " " << gMC->CurrentVolOffName(0) << " "
184 // " " << vol->getRealName() << " " << gMC->CurrentVolPath() <<
185 // " ivol,iCell,copyNo= " << ivol << ","<< iCell << ","<< copyNo <<
186 // " " << vol->getRealName() << " "<< gMC->CurrentVolName() << " "<< gMC->CurrentVolPath() <<
187 // " " << ivol << ","<< vol->getVolumeId() << " : "<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
188 // " "<< gMC->CurrentVolOffName(2) << " " <<
189 // " "<< gMC->CurrentVolOffName(2) << " "<< gMC->CurrentVolOffName(3) <<
190 std::endl;
191 // vol->getGeoNode()->getMotherNode()->getMotherNode()->getCenterPosition().print();
192 lEDEBUGcounter++;
193 }
194 if ((iCell==2)&&(lEDEBUGcounter>=100)&&(!already)) {
195 already=1;
196 lEDEBUGcounter=0;
197 }
198// if ((part->GetPdgCode())==321) {
199// std::cout << "EDEBUG-- BmnZdc::ProcessHits(..) K+: " << fTrackID << " " << ( gMC->IsTrackExiting()) << " " <<
200// (gMC->IsTrackStop()) << " " << (gMC->IsTrackDisappeared()) << " " << fELoss << " " << time << std::endl;
201// }
202//#endif
203
204// if(copyNo==1)
205// AddHit(fTrackID, ivol, copyNo, iCell, TVector3(tPos1.X(), tPos1.Y(), tPos1.Z()),
206// TVector3(tMom1.Px(), tMom1.Py(), tMom1.Pz()),
207// time, length, fELoss);
208// else
209
210 AddHit(fTrackID, ivol, copyNo_slice, copyNo, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
211 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
212 time, length, fELoss);
213#else
214
215 AddHit(fTrackID, ivol, copyNo_slice, copyNo, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
216 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
217 time, length, fELoss);
218#endif
219
220 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
221// Int_t nZdcPoints = (points & (1<<30)) >> 30;
222// nZdcPoints ++;
223// if (nZdcPoints > 1) nZdcPoints = 1;
224// points = ( points & ( ~ (1<<30) ) ) | (nZdcPoints << 30);
225 points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
226 gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
227
228 ((CbmStack*)gMC->GetStack())->AddPoint(kZDC);
229
230 }
231
232// Int_t copyNo;
233// gMC->CurrentVolID(copyNo);
234// TString nam = gMC->GetMC()->GetName();
235 // cout<<"name "<<gMC->GetMC()->GetName()<<endl;
236 // ResetParameters();
237
238 return kTRUE;
239
240 // }
241#undef EDEBUG
242}
243
244// ----------------------------------------------------------------------------
245
246// ----- Public method EndOfEvent -----------------------------------------
247void BmnZdc::EndOfEvent() {
248 if (fVerboseLevel) Print();
249 Reset();
250}
251
252
253// ----- Public method Register -------------------------------------------
254void BmnZdc::Register() {
255 FairRootManager::Instance()->Register("ZdcPoint","Zdc", fZdcCollection, kTRUE);
256}
257
258
259// ----- Public method GetCollection --------------------------------------
260TClonesArray* BmnZdc::GetCollection(Int_t iColl) const {
261 if (iColl == 0) return fZdcCollection;
262
263 return NULL;
264}
265
266
267// ----- Public method Print ----------------------------------------------
268void BmnZdc::Print() const {
269 Int_t nHits = fZdcCollection->GetEntriesFast();
270 cout << "-I- BmnZdc: " << nHits << " points registered in this event."
271 << endl;
272
273 if (fVerboseLevel>1)
274 for (Int_t i=0; i<nHits; i++) (*fZdcCollection)[i]->Print();
275}
276
277
278
279
280// ----- Public method Reset ----------------------------------------------
281void BmnZdc::Reset() {
282 fZdcCollection->Delete();
283
284 fPosIndex = 0;
285}
286
287
288// guarda in FairRootManager::CopyClones
289// ----- Public method CopyClones -----------------------------------------
290void BmnZdc::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
291 Int_t nEntries = cl1->GetEntriesFast();
292 //cout << "-I- BmnZdc: " << nEntries << " entries to add." << endl;
293 TClonesArray& clref = *cl2;
294 BmnZdcPoint* oldpoint = NULL;
295 for (Int_t i=0; i<nEntries; i++) {
296 oldpoint = (BmnZdcPoint*) cl1->At(i);
297 Int_t index = oldpoint->GetTrackID() + offset;
298 oldpoint->SetTrackID(index);
299 new (clref[fPosIndex]) BmnZdcPoint(*oldpoint);
300 fPosIndex++;
301 }
302 cout << " -I- BmnZdc: " << cl2->GetEntriesFast() << " merged entries."
303 << endl;
304}
305
306 // ----- Public method ConstructGeometry ----------------------------------
307
309
310 TString fileName = GetGeometryFileName();
311 if(fileName.EndsWith(".root"))
312 {
313 //FairLogger::GetLogger()->Info(MESSAGE_ORIGIN, "Constructing ZDC geometry from ROOT file %s", fileName.Data());
314 LOG(info) << "Constructing ZDC geometry from ROOT file" <<fileName.Data();
315 ConstructRootGeometry();
316 }
317
318 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
319 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
320 BmnZdcGeo* zdcGeo = new BmnZdcGeo();
321 zdcGeo->setGeomFile(GetGeometryFileName());
322 geoFace->addGeoModule(zdcGeo);
323
324 Bool_t rc = geoFace->readSet(zdcGeo);
325 if (rc) zdcGeo->create(geoLoad->getGeoBuilder());
326 TList* volList = zdcGeo->getListOfVolumes();
327
328 // store geo parameter
329 FairRun *fRun = FairRun::Instance();
330 FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb();
331 BmnZdcGeoPar* par=(BmnZdcGeoPar*)(rtdb->getContainer("BmnZdcGeoPar"));
332 TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
333 TObjArray *fPassNodes = par->GetGeoPassiveNodes();
334
335 TListIter iter(volList);
336 FairGeoNode* node = NULL;
337 FairGeoVolume *aVol=NULL;
338
339 while( (node = (FairGeoNode*)iter.Next()) ) {
340 aVol = dynamic_cast<FairGeoVolume*> ( node );
341
342
343 if ( node->isSensitive() ) {
344 fSensNodes->AddLast( aVol );
345 }else{
346 fPassNodes->AddLast( aVol );
347 }
348 }
349 par->setChanged();
350 par->setInputVersion(fRun->GetRunId(),1);
351
352 ProcessNodes ( volList );
353}
354
355//Check if Sensitive-----------------------------------------------------------
356Bool_t BmnZdc::CheckIfSensitive(std::string name) {
357 TString tsname = name;
358 if (tsname.Contains("zdc01s") || tsname.Contains("ScH")) {
359 return kTRUE;
360 }
361 return kFALSE;
362}
363
364
365// ----- Private method AddHit --------------------------------------------
366//BmnZdcPoint* BmnZdc::AddHit(Int_t trackID, Int_t module_groupID, Int_t copyNo, Int_t copyNoMother,
367BmnZdcPoint* BmnZdc::AddHit(Int_t trackID, Int_t detID, Int_t copyNo, Int_t copyNoMother,
368 TVector3 pos, TVector3 mom, Double_t time,
369 Double_t length, Double_t eLoss) {
370 TClonesArray& clref = *fZdcCollection;
371 Int_t size = clref.GetEntriesFast();
372 return new(clref[size]) BmnZdcPoint(trackID, detID, copyNo, copyNoMother,pos, mom,
373 time, length, eLoss);
374}
int i
Definition P4_F32vec4.h:22
@ kZDC
TObjArray * GetGeoPassiveNodes()
TObjArray * GetGeoSensitiveNodes()
virtual void Print() const
virtual void EndOfEvent()
Definition BmnZdc.cxx:408
virtual void Reset()
Definition BmnZdc.cxx:442
virtual void ConstructGeometry()
Definition BmnZdc.cxx:469
BmnZdc()
Definition BmnZdc.cxx:44
virtual Bool_t CheckIfSensitive(std::string name)
Definition BmnZdc.cxx:517
BmnZdcPoint * AddHit(Int_t trackID, Int_t detID, Int_t copyNo, Int_t copyNoMother, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss)
Definition BmnZdc.cxx:529
virtual void CopyClones(TClonesArray *cl1, TClonesArray *cl2, Int_t offset)
Definition BmnZdc.cxx:451
virtual ~BmnZdc()
Definition BmnZdc.cxx:76
virtual void BeginEvent()
Definition BmnZdc.cxx:100
virtual TClonesArray * GetCollection(Int_t iColl) const
Definition BmnZdc.cxx:421
virtual void Register()
Definition BmnZdc.cxx:415
virtual void Initialize()
Definition BmnZdc.cxx:88
virtual Bool_t ProcessHits(FairVolume *vol=0)
Definition BmnZdc.cxx:109
name
Definition setup.py:7