BmnRoot
Loading...
Searching...
No Matches
BmnZdc.FWall.vacuum_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 //cout <<"Initialize marina " <<endl;
87 FairDetector::Initialize();
88 FairRun* sim = FairRun::Instance();
89 FairRuntimeDb* rtdb=sim->GetRuntimeDb();
90}
91// -------------------------------------------------------------------------
93 // Begin of the event
94 //cout <<"BeginEvent marina " <<endl;
95
96}
97
98
99
100// ----- Public method ProcessHits --------------------------------------
101Bool_t BmnZdc::ProcessHits(FairVolume* vol) {
102
103 //cout <<"ProcessHits marina " <<endl;
104 // if (TMath::Abs(gMC->TrackCharge()) <= 0) return kFALSE;
105
106 Int_t ivol = vol->getMCid();
107 TLorentzVector tPos1, tMom1;
108
109 //#define EDEBUG
110#ifdef EDEBUG
111 static Int_t lEDEBUGcounter=0;
112 if (lEDEBUGcounter<1)
113 std::cout << "EDEBUG-- BmnZdc::ProcessHits: entered" << gMC->CurrentVolPath() << endl;
114#endif
115
116 if (gMC->IsTrackEntering()) {
117
118 ResetParameters();
119 fELoss = 0.;
120#ifdef EDEBUG
121 gMC->TrackPosition(tPos1);
122 gMC->TrackMomentum(tMom1);
123#endif
124 }
125
126 Double_t eLoss = gMC->Edep();
127 if (eLoss != 0.)
128 fELoss += eLoss;
129
130 if ( gMC->IsTrackExiting() ||
131 gMC->IsTrackStop() ||
132 gMC->IsTrackDisappeared() ) {
133
134//commented for vacuum FWall
135/*
136#ifndef EDEBUG
137 if (fELoss == 0. ) return kFALSE;
138#else
139 if ((fELoss == 0. ) &&
140 (!((gMC->GetStack()->GetCurrentTrack()->GetPdgCode()==2112)&&(gMC->GetStack()->GetCurrentTrack()->GetMother(0)==-1)))
141) return kFALSE;
142#endif
143*/
144//END comment for vacuum FWall
145
146 TParticle* part = gMC->GetStack()->GetCurrentTrack();
147 Double_t charge = part->GetPDG()->Charge() / 3. ;
148
149 // Create BmnZdcPoint
150 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
151 Double_t time = gMC->TrackTime() * 1.0e09;
152 Double_t length = gMC->TrackLength();
153 TLorentzVector tPos, tMom;
154 gMC->TrackPosition(tPos);
155 gMC->TrackMomentum(tMom);
156
157 /*
158 //old geom
159 Int_t copyNo;
160 Int_t ivol1 = gMC->CurrentVolID(copyNo);
161 // ivol1 = vol->getVolumeId();
162 Int_t iCell, iCell2 ;
163 gMC->CurrentVolOffID(1, iCell);
164 gMC->CurrentVolOffID(2, iCell2);
165 */
166
167 //new geom
168 Int_t copyNo;
169 Int_t copyNo_slice;
170 Int_t ivol1 = gMC->CurrentVolID(copyNo_slice);
171 // ivol1 = vol->getVolumeId();
172 Int_t iCell, iCell2 ;
173 gMC->CurrentVolOffID(1, copyNo);
174
175
176#ifdef EDEBUG
177 static Bool_t already=0;
178 if (lEDEBUGcounter<200) {
179 std::cout << "EDEBUG-- BmnZdc::ProcessHits: TrackID:" << fTrackID <<
180 // " ELoss: " << fELoss <<
181 // " particle: " << (part->GetName()) <<
182 " " << gMC->CurrentVolPath() << " " << tPos.X()<< " " << tPos.Y() << " " << tPos.Z() << " " << part->GetPDG()->PdgCode()<<
183 // " " << (gMC->GetStack()->GetCurrentTrack()->GetMother(1)) <<
184 // " " << ivol << "=="<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
185 " " << ivol << " " << vol->getRealName() << " " <<
186 " " << gMC->CurrentVolOffID(1,iCell) << " " << gMC->CurrentVolOffName(1) <<
187 " " << iCell << " " << iCell2 << " "<< gMC->CurrentVolOffName(2) <<
188 " " << vol->getModId()<< " " <<
189 // " " << gMC->CurrentVolOffName(2) << " " << gMC->CurrentVolOffName(1) << " " << gMC->CurrentVolOffName(0) << " "
190 // " " << vol->getRealName() << " " << gMC->CurrentVolPath() <<
191 // " ivol,iCell,copyNo= " << ivol << ","<< iCell << ","<< copyNo <<
192 // " " << vol->getRealName() << " "<< gMC->CurrentVolName() << " "<< gMC->CurrentVolPath() <<
193 // " " << ivol << ","<< vol->getVolumeId() << " : "<< gMC->CurrentVolID(copyNo) << ","<< copyNo <<
194 // " "<< gMC->CurrentVolOffName(2) << " " <<
195 // " "<< gMC->CurrentVolOffName(2) << " "<< gMC->CurrentVolOffName(3) <<
196 std::endl;
197 // vol->getGeoNode()->getMotherNode()->getMotherNode()->getCenterPosition().print();
198 lEDEBUGcounter++;
199 }
200 if ((iCell==2)&&(lEDEBUGcounter>=100)&&(!already)) {
201 already=1;
202 lEDEBUGcounter=0;
203 }
204// if ((part->GetPdgCode())==321) {
205// std::cout << "EDEBUG-- BmnZdc::ProcessHits(..) K+: " << fTrackID << " " << ( gMC->IsTrackExiting()) << " " <<
206// (gMC->IsTrackStop()) << " " << (gMC->IsTrackDisappeared()) << " " << fELoss << " " << time << std::endl;
207// }
208//#endif
209
210// if(copyNo==1)
211// AddHit(fTrackID, ivol, copyNo, iCell, TVector3(tPos1.X(), tPos1.Y(), tPos1.Z()),
212// TVector3(tMom1.Px(), tMom1.Py(), tMom1.Pz()),
213// time, length, fELoss);
214// else
215
216 AddHit(fTrackID, ivol, copyNo_slice, copyNo, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
217 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
218 time, length, fELoss);
219#else
220
221 AddHit(fTrackID, ivol, copyNo_slice, copyNo, TVector3(tPos.X(), tPos.Y(), tPos.Z()),
222 TVector3(tMom.Px(), tMom.Py(), tMom.Pz()),
223 time, length, fELoss);
224#endif
225
226 Int_t points = gMC->GetStack()->GetCurrentTrack()->GetMother(1);
227// Int_t nZdcPoints = (points & (1<<30)) >> 30;
228// nZdcPoints ++;
229// if (nZdcPoints > 1) nZdcPoints = 1;
230// points = ( points & ( ~ (1<<30) ) ) | (nZdcPoints << 30);
231 points = ( points & ( ~ (1<<30) ) ) | (1 << 30);
232 gMC->GetStack()->GetCurrentTrack()->SetMother(1,points);
233
234 ((CbmStack*)gMC->GetStack())->AddPoint(kZDC);
235
236 }
237
238// Int_t copyNo;
239// gMC->CurrentVolID(copyNo);
240// TString nam = gMC->GetMC()->GetName();
241 // cout<<"name "<<gMC->GetMC()->GetName()<<endl;
242 // ResetParameters();
243
244 return kTRUE;
245
246 // }
247#undef EDEBUG
248}
249
250// ----------------------------------------------------------------------------
251
252// ----- Public method EndOfEvent -----------------------------------------
253void BmnZdc::EndOfEvent() {
254 if (fVerboseLevel) Print();
255 Reset();
256}
257
258
259// ----- Public method Register -------------------------------------------
260void BmnZdc::Register() {
261 FairRootManager::Instance()->Register("ZdcPoint","Zdc", fZdcCollection, kTRUE);
262}
263
264
265// ----- Public method GetCollection --------------------------------------
266TClonesArray* BmnZdc::GetCollection(Int_t iColl) const {
267 if (iColl == 0) return fZdcCollection;
268
269 return NULL;
270}
271
272
273// ----- Public method Print ----------------------------------------------
274void BmnZdc::Print() const {
275 Int_t nHits = fZdcCollection->GetEntriesFast();
276 cout << "-I- BmnZdc: " << nHits << " points registered in this event."
277 << endl;
278
279 if (fVerboseLevel>1)
280 for (Int_t i=0; i<nHits; i++) (*fZdcCollection)[i]->Print();
281}
282
283
284
285
286// ----- Public method Reset ----------------------------------------------
287void BmnZdc::Reset() {
288 fZdcCollection->Delete();
289
290 fPosIndex = 0;
291}
292
293
294// guarda in FairRootManager::CopyClones
295// ----- Public method CopyClones -----------------------------------------
296void BmnZdc::CopyClones(TClonesArray* cl1, TClonesArray* cl2, Int_t offset ) {
297 Int_t nEntries = cl1->GetEntriesFast();
298 //cout << "-I- BmnZdc: " << nEntries << " entries to add." << endl;
299 TClonesArray& clref = *cl2;
300 BmnZdcPoint* oldpoint = NULL;
301 for (Int_t i=0; i<nEntries; i++) {
302 oldpoint = (BmnZdcPoint*) cl1->At(i);
303 Int_t index = oldpoint->GetTrackID() + offset;
304 oldpoint->SetTrackID(index);
305 new (clref[fPosIndex]) BmnZdcPoint(*oldpoint);
306 fPosIndex++;
307 }
308 cout << " -I- BmnZdc: " << cl2->GetEntriesFast() << " merged entries."
309 << endl;
310}
311
312 // ----- Public method ConstructGeometry ----------------------------------
313
315
316 TString fileName = GetGeometryFileName();
317 if(fileName.EndsWith(".root"))
318 {
319 //FairLogger::GetLogger()->Info(MESSAGE_ORIGIN, "Constructing ZDC geometry from ROOT file %s", fileName.Data());
320 LOG(info) << "Constructing ZDC geometry from ROOT file" <<fileName.Data();
321 ConstructRootGeometry();
322 }
323
324 FairGeoLoader* geoLoad = FairGeoLoader::Instance();
325 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
326 BmnZdcGeo* zdcGeo = new BmnZdcGeo();
327 zdcGeo->setGeomFile(GetGeometryFileName());
328 geoFace->addGeoModule(zdcGeo);
329
330 Bool_t rc = geoFace->readSet(zdcGeo);
331 if (rc) zdcGeo->create(geoLoad->getGeoBuilder());
332 TList* volList = zdcGeo->getListOfVolumes();
333
334 // store geo parameter
335 FairRun *fRun = FairRun::Instance();
336 FairRuntimeDb *rtdb= FairRun::Instance()->GetRuntimeDb();
337 BmnZdcGeoPar* par=(BmnZdcGeoPar*)(rtdb->getContainer("BmnZdcGeoPar"));
338 TObjArray *fSensNodes = par->GetGeoSensitiveNodes();
339 TObjArray *fPassNodes = par->GetGeoPassiveNodes();
340
341 TListIter iter(volList);
342 FairGeoNode* node = NULL;
343 FairGeoVolume *aVol=NULL;
344
345 while( (node = (FairGeoNode*)iter.Next()) ) {
346 aVol = dynamic_cast<FairGeoVolume*> ( node );
347
348
349 if ( node->isSensitive() ) {
350 fSensNodes->AddLast( aVol );
351 }else{
352 fPassNodes->AddLast( aVol );
353 }
354 }
355 par->setChanged();
356 par->setInputVersion(fRun->GetRunId(),1);
357
358 ProcessNodes ( volList );
359}
360
361//Check if Sensitive-----------------------------------------------------------
362Bool_t BmnZdc::CheckIfSensitive(std::string name) {
363 TString tsname = name;
364 if (tsname.Contains("zdc01s") || tsname.Contains("ScH")) {
365 return kTRUE;
366 }
367 return kFALSE;
368}
369
370
371// ----- Private method AddHit --------------------------------------------
372//BmnZdcPoint* BmnZdc::AddHit(Int_t trackID, Int_t module_groupID, Int_t copyNo, Int_t copyNoMother,
373BmnZdcPoint* BmnZdc::AddHit(Int_t trackID, Int_t detID, Int_t copyNo, Int_t copyNoMother,
374 TVector3 pos, TVector3 mom, Double_t time,
375 Double_t length, Double_t eLoss) {
376 TClonesArray& clref = *fZdcCollection;
377 Int_t size = clref.GetEntriesFast();
378 return new(clref[size]) BmnZdcPoint(trackID, detID, copyNo, copyNoMother,pos, mom,
379 time, length, eLoss);
380}
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