// ------------------------------------------------------------------------- // ----- PndDrc source file ----- // ----- Created 11/10/06 by Annalisa Cecchi ----- // ----- Modified 2006++ by Carsten Schwarz ----- // ----- Modified 2010++ by Maria Patsyuk ----- // ----- ----- // ------------------------------------------------------------------------- #include "PndGeoDrc.h" #include "PndDrcPDPoint.h" #include "PndDrcBarPoint.h" #include "PndGeoDrcPar.h" #include "PndDetectorList.h" #include "PndDrc.h" #include "TString.h" //#include using std::endl; using std::cout; #include "TClonesArray.h" #include "TVirtualMC.h" #include "TObjArray.h" #include "TGeoMCGeometry.h" #include "TGeoManager.h" #include "TLorentzVector.h" #include "TParticle.h" #include "TVirtualMC.h" #include "TGeoPgon.h" #include "TGeoSphere.h" #include "TGeoBBox.h" #include "TGeoArb8.h" #include "TGeoCone.h" #include "TGeoTrd2.h" #include "TGeoCompositeShape.h" #include "TGeoMatrix.h" #include "TGeoManager.h" #include "TObject.h" #include "TColor.h" #include "TCanvas.h" #include "FairGeoInterface.h" #include "FairGeoLoader.h" #include "FairGeoNode.h" #include "FairRootManager.h" #include "FairVolume.h" #include "FairGeoMedia.h" #include "FairGeoMedium.h" #include "FairGeoRootBuilder.h" #include "PndStack.h" #include "PndDetectorList.h" // add on for debug //#include "FairGeoG3Builder.h" #include "FairRun.h" //#include "FairRunSim.h" #include "FairRuntimeDb.h" #include // ----- Default constructor ------------------------------------------- PndDrc::PndDrc() : FairDetector("PndDrcDefault",kTRUE), fpi(TMath::Pi()), //! fzup(-999.), //! fzdown(-999.), fradius(-999.), fhthick(-999.), fpipehAngle(-999.), fbbGap(-999.), fbbnum(-999.), fbarnum(-999.), fphi0(-999.), fdphi(-999.), flside(-999.), fbarwidth(-999.), fRunCherenkov(kTRUE), //! Switch ON/OFF Cherenkov propagation fTrackID(-1), //! track index fCurrentTrackID(-1), //! track index fCopyNo(-1), //! volume id fPos(TLorentzVector(0,0,0)), //! position fMom(TLorentzVector(0,0,0)), //! momentum fTime(-1), //! time fLength(-1), //! length fAngIn(0), fNBar(0), fPosIndex(-1), //! volDetector(0), //! MC volume ID of drc fMass(-1), fMom1(TLorentzVector(0,0,0)), fMom2(TLorentzVector(0,0,0)), //! for transport efficiency calculation fPos2(TLorentzVector(0,0,0)), //! for transport efficiency calculation fBarEnd(0), fMirrorGap(0), // for efficiency calculation: //fLambda({0}), //fEfficiency({0}), //fEfficiencyR({0}), fLambdaMin(0.), fLambdaMax(0.), fLambdaStep(0.), fAngleStep(0.), fLambdaPoints(0), // used in ProcessHits function: fbarID(0), //! ID number of DrcBarSensors fpdID(0), //! ID number of DrcPdSensor flens3ID(0), //! ID number of third lenses flens2ID(0), flens1ID(0), fbboxID(0), //! ID number of DrcBarBoxes fevID(0), //! ID number of Expansion Volume fDetEff(0x0), //! Detector Efficiency as a function of photon wavelength fDetEffAtProduction(kFALSE), fTransportEffAtProduction(kFALSE), frand(), fLastTrackID(-1), fCollectionEff(-1),//Collection Efficiency fPackingFraction(-1),//Packing Efficiency fStopTime(kFALSE), fPhoMaxTime(-1), fTakeDirect(kFALSE), fTakeReflected(kFALSE), fFocusing(-1), fTakeRealReflectivity(kFALSE), fStopSecondaries(kFALSE), fGeo(new PndGeoDrc()), //! Pointer to basic DRC geometry data fPdgCode(-1), fThetaC(-1.), fDrcPDCollection(new TClonesArray("PndDrcPDPoint")), //! Hit collection fDrcBarCollection (new TClonesArray("PndDrcBarPoint")), //! Hit collection in the bar fEventID(0), fSenId1(0), fSenId2(0), fSenIdBar(0) { fListOfSensitives.push_back("Sensor"); if(fVerboseLevel > 0){ std::cout<<"-I- PndBarrelDIRC: fListOfSensitives contains:"; for(Int_t k=0; k 0){ std::cout<<"-I- PndBarrelDIRC: fListOfSensitives contains:"; for(Int_t k=0; kDelete(); delete fDrcPDCollection; } if (fDrcBarCollection) { fDrcBarCollection->Delete(); delete fDrcBarCollection; } if (fGeo) delete fGeo; } // ------------------------------------------------------------------------- // ----- Public method Intialize --------------------------------------- void PndDrc::Initialize() { cout << " -I- PndDrc: Intialization started... " << endl; FairDetector::Initialize(); //FairRun *sim = FairRun::Instance(); //FairRuntimeDb *rtdb = sim->GetRuntimeDb(); //PndGeoDrcPar *par = (PndGeoDrcPar*)(rtdb->getContainer("PndGeoDrcPar")); if (fRunCherenkov==kFALSE) cout << " -I- PndDrc: Switching OFF Cherenkov Propagation" << endl; // basic DIRC parameters: fpi = TMath::Pi(); fzup = fGeo->barBoxZUp(); fzdown = fGeo->barBoxZDown(); fradius = fGeo->radius(); //radius in the middle of the bar = 50.cm fhthick = fGeo->barHalfThick(); //half thickness of the bars=1.7/2 cm fpipehAngle = fGeo->PipehAngle(); fbbGap = fGeo->BBoxGap(); fbbnum = fGeo->BBoxNum(); fbarnum = fGeo->barNum(); fphi0 = (180.-2.*fpipehAngle)/fbbnum + fpipehAngle; fdphi = (180.-2.*fpipehAngle)/fbbnum*2.; flside = fGeo->Lside(); fbarwidth = fGeo->BarWidth(); cout<<"DRC parameters: fpi = "<VolId("DrcLENS2Sensor"); flens1ID = gMC->VolId("DrcLENS1Sensor"); //cout<<"lens1 = "<FindNode("DrcLENS1Sensor_1")->GetVolume()->GetNumber()<< // ", lens2 = "<FindNode("DrcLENS2Sensor_1")->GetVolume()->GetNumber()<< // ", lens3 = "<FindNode("DrcLENS3Sensor_1")->GetVolume()->GetNumber()<VolId("DrcLENS2Sensor"); flens1ID = gMC->VolId("DrcLENS1Sensor"); //cout<<"lens1 = "<FindNode("DrcLENS1Sensor_1")->GetVolume()->GetNumber()<< // ", lens2 = "<FindNode("DrcLENS2Sensor_1")->GetVolume()->GetNumber()<0) cout<<" \n\n>>>>>>>>>>>>>>>>>>>>new event in the Barrel DIRC" <GetName(); //cout<<"-I- PndDrc: vol nam = "<getMCid(); //Register points in the barrel (PndDrcBarPoints) fEventID = gMC->CurrentEvent(); fPdgCode = gMC->TrackPid(); //TLorentzVector fPos, fMom; gMC->TrackPosition(fPos); //$$$$$$$$$$$$$$$$$$$$$$ //stop secondaries so that they do not produce Cherenkov photons if(fStopSecondaries){ if(fPdgCode != 50000050){ if(gMC->GetStack()->GetCurrentParentTrackNumber() != -1 ){ if(gMC->IsTrackEntering()){ gMC->StopTrack(); } } } } //$$$$$$$$$$$$$$$$$$$$$$ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ /* // stop muon or pion or kaon immediately after DIRC if(fabs(fPdgCode) == 211 || fabs(fPdgCode) == 13 || fabs(fPdgCode) == 321){ //cout<<"pos: x = "< fradius+1.5){ //cout<<"pos: x = "<StopTrack(); } } } if(sqrt(fPos.X()*fPos.X() + fPos.Y()*fPos.Y()) > fradius+5.){ gMC->StopTrack(); } } */ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ if (fPdgCode == 50000050){ if (fRunCherenkov==kFALSE ) { gMC->StopTrack(); if (fVerboseLevel >0) cout<< "Photon killed" << endl; } //$$$$$$$$$$$$$$$$$$$$$$$$$$$ /* if(num == fbarID && fLastTrackID != gMC->GetStack()->GetCurrentTrackNumber()){ // check how many photons were born nphotons = nphotons + 1; cout<<"photon number "<StopTrack(); }*/ //$$$$$$$$$$$$$$$$$$$$$$$$$$$ // apply detector efficiency at the production stage: if(fDetEffAtProduction && fLastTrackID != gMC->GetStack()->GetCurrentTrackNumber()){ //cout<<"-I- PndDrc: DET EFF IS APPLIED!!!"<TrackMomentum(fMom1); Double_t Px= fMom1.Px(); Double_t Py= fMom1.Py(); Double_t Pz= fMom1.Pz(); Double_t fP = sqrt(Px*Px + Py*Py +Pz*Pz); Double_t lambda=197.0*2.0*fpi/(fP*1.0E9); Double_t ra = frand.Uniform(0., 1.); if(ra > fDetEff->Eval(lambda)){ gMC->StopTrack(); } } //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // apply transport efficiency at production stage: // Maria Patsyuk 20.04.2012 if(fTransportEffAtProduction && fLastTrackID != gMC->GetStack()->GetCurrentTrackNumber()){ gMC->TrackMomentum(fMom2); // initial momentum of the photon TVector3 PphoInit; PphoInit.SetXYZ(fMom2.Px(),fMom2.Py(),fMom2.Pz()); Double_t P_tr = sqrt(pow(PphoInit.X(),2) + pow(PphoInit.Y(),2) + pow(PphoInit.Z(),2)); Double_t lam_tr = (197.0*2.0*fpi/(P_tr*1.0E9)) / 1000.; //cout<<"lam = "<TrackPosition(fPos2); // production point of the photon TVector3 StartVertex; StartVertex.SetXYZ(fPos2.X(), fPos2.Y(), fPos2.Z()); //cout<<"production point = "<IsTrackExiting()==1){ if(num == flens3ID && fPos.Z() < fBarEnd){ //cout<<"fBarEnd = "<TrackPosition(fPos); gMC->TrackMomentum(fMom); if ((fPos.X()*fMom.X() + fPos.Y()*fMom.Y()) < 0.){ gMC->StopTrack(); } } } } // "TakeOnlyReflectedPho" option: // if photon is exiting the bar - check its direction if(fTakeReflected){ if(gMC->IsTrackExiting()==1){ if(num == flens3ID && fPos.Z() < fBarEnd){ //std::cout<<"Track is exiting the "<TrackPosition(fPos); gMC->TrackMomentum(fMom); if ((fPos.X()*fMom.X() + fPos.Y()*fMom.Y()) > 0.){ gMC->StopTrack(); } } } } // kill photons older than fPhoMaxTime: if (fStopTime == kTRUE && gMC->TrackTime()*1.0e09 > fPhoMaxTime){ gMC->StopTrack(); } if (gMC->IsTrackEntering()==1){ if( num == fpdID){ //if (nam.BeginsWith("DrcPD")){ fCopyNo = vol->getCopyNo(); fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); //track ID gMC->TrackPosition(fPos); gMC->TrackMomentum(fMom); // GeV/c fTime=gMC->TrackTime()*1.0e09; // ns fLength = gMC->TrackLength(); // cm ?? AddHit(fTrackID, fCopyNo, TVector3(fPos.X(), fPos.Y(), fPos.Z()), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fPdgCode, fEventID); } PndStack* stack = (PndStack*) gMC->GetStack(); stack->AddPoint(kDRC); } }else if(gMC->TrackCharge()!=0. && gMC->IsTrackEntering()==1 ){ //if (nam.BeginsWith("DrcBar")) { if(num == fbarID){ // Double_t fCharge = gMC->TrackCharge(); fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); if(fTrackID!=fCurrentTrackID){ fTime = gMC->TrackTime() * 1.0e09; fLength = gMC->TrackLength(); // Int_t copyNo = vol->getCopyNo(); Int_t s=0, b=0; //side and bar fNBar=0; TString path = gMC->CurrentVolPath(); //cout<<"+++++++++++++++++++++++++++++++++"<CurrentVolPath() << endl; //cout<<"+++++++++++++++++++++++++++++++++"<0) cout<< "Volume: " << gMC->CurrentVolPath() << endl; sscanf(path, "/cave_1/BarrelDIRC_0/DrcBarBox_%d/DrcAirBox_0/DrcBarSensor_%d", &s, &b); //cout<<"side no.= "<= 0. && x1 + xEn <= a){xK = x1 + xEn;} if(x0 >= 0. && x1 + xEn > a){xK = 2*a - x1 - xEn; n = 1. + n;} if(x0 < 0. && x1 + xEn >= 0.){xK = a - (x1 + xEn); n = -1. -n;} if(x0 < 0. && x1 + xEn < 0.) {xK = a + x1 + xEn; n = -n;} if(print){std::cout<<"xK = "<< xK<<", n = "<= 0. && x1 + xEn <= a){xK = a - (x1 + xEn);} if(x0 >= 0. && x1 + xEn > a){xK = x1 + xEn - a; n = 1. + n;} if(x0 < 0. && x1 + xEn >= 0.){xK = x1 + xEn; n = -1. -n;} if(x0 < 0. && x1 + xEn < 0.) {xK = - (x1 + xEn); n = -n;} if(print){std::cout<<"xK = "<< xK<<", n = "<Register("DrcBarPoint","Drc", fDrcBarCollection, kTRUE); FairRootManager::Instance()->Register("DrcPDPoint","Drc", fDrcPDCollection, kTRUE); } // ---------------------------------------------------------------------------- // ----- Public method GetCollection -------------------------------------- TClonesArray* PndDrc::GetCollection(Int_t iColl) const { if (iColl == 0) return fDrcPDCollection; if (iColl == 1) return fDrcBarCollection; return NULL; } // ---------------------------------------------------------------------------- // ----- Public method Print ---------------------------------------------- void PndDrc::Print() const { Int_t nPDHits = fDrcPDCollection->GetEntriesFast(); Int_t nbarHits = fDrcBarCollection->GetEntriesFast(); cout << "-I- PndDrc: " << nPDHits << " points registered in the photodetector for this event." << endl; cout << "-I- PndDrc: " << nbarHits << " points registered in the bar for this event." << endl; if (fVerboseLevel>1){ for (Int_t i=0; iPrint(); for (Int_t i=0; iPrint(); } } // ---------------------------------------------------------------------------- // ----- Public method Reset ---------------------------------------------- void PndDrc::Reset() { fDrcPDCollection->Delete(); fDrcBarCollection->Delete(); fPosIndex = 0; } // ---------------------------------------------------------------------------- // guarda in FairRootManager::CopyClones // ----- Public method CopyClones ----------------------------------------- void PndDrc::CopyClones(TClonesArray* clPD1, TClonesArray* clPD2,TClonesArray* clBar1, TClonesArray* clBar2, Int_t offset ) { Int_t nPDEntries = clPD1->GetEntriesFast(); cout << "-I- PndDrc: " << nPDEntries << " entries to add." << endl; TClonesArray& clrefPD = *clPD2; Int_t nBarEntries = clBar1->GetEntriesFast(); cout << "-I- PndDrc: " << nBarEntries << " entries to add." << endl; TClonesArray& clrefBar = *clBar2; PndDrcPDPoint* oldpointPD = NULL; PndDrcBarPoint* oldpointBar = NULL; for (Int_t i=0; iAt(i); Int_t indexPD = oldpointPD->GetTrackID() + offset; oldpointPD->SetTrackID(indexPD); new (clrefPD[fPosIndex]) PndDrcPDPoint(*oldpointPD); fPosIndex++; } for (Int_t i=0; iAt(i); Int_t indexBar = oldpointBar->GetTrackID() + offset; oldpointBar->SetTrackID(indexBar); new (clrefBar[fPosIndex]) PndDrcBarPoint(*oldpointBar); fPosIndex++; } cout << " -I- PndDrc: " << clPD2->GetEntriesFast() << " merged entries." << endl; cout << " -I- PndDrc: " << clBar2->GetEntriesFast() << " merged entries." << endl; } // ---------------------------------------------------------------------------- // ----- Public method ConstructGeometry ----------------------------------- void PndDrc::ConstructGeometry() { cout<< " " << endl; cout<< " ======= DRC:: ConstructGeometry() ======== " << endl; cout<< " ============================================= " << endl; TString fileName = GetGeometryFileName(); if(fileName.EndsWith(".root")){ ConstructRootGeometry(); if(fileName.Contains("_l0_")){ fBarEnd = -119.999; fFocusing = 0; } if(fileName.Contains("_l2_")){ fBarEnd = -119.999; fFocusing = 2; } if(fileName.Contains("_l1_")){ fBarEnd = -118.725; fFocusing = 1; } if(fileName.Contains("_l3_")){ fBarEnd = -119.8; fFocusing = 3; //cout<<"focusing = "<DefineOpSurface("BarSurface", kGlisur, kDielectric_dielectric, kPolished, 0.0); gMC->DefineOpSurface("MirrSurface", kGlisur, kDielectric_metal, kPolished, 0.0); if(fGeo->barNum() > 1){ for(Int_t i=0; ibarNum(); i++){ //gMC->SetBorderSurface("BarAirSurface", "DrcBarSensor", i+1, "DrcAirBox", 0, "BarSurface"); if(fFocusing == 1 || fFocusing == 0 || fFocusing == 3){ // lens or no focusing if(fMirrorGap == 0.){ //gMC->SetBorderSurface("Lens1AirSurface", "DrcLENS1", i+1, "DrcAirBox", 0, "BarSurface"); //gMC->SetBorderSurface("Lens2AirSurface", "DrcLENS2", i+1, "DrcAirBox", 0, "BarSurface"); //gMC->SetBorderSurface("Lens3AirSurface", "DrcLENS3", i+1, "DrcAirBox", 0, "BarSurface"); gMC->SetBorderSurface("BarMirrSurface", "DrcBarSensor", i+1, "DrcMirr", i+1, "MirrSurface"); } } } } if(fMirrorGap > 0.){ gMC->SetSkinSurface("AirMirrorSurface", "DrcMirr", "MirrSurface"); } if(fTakeRealReflectivity == kFALSE){ gMC->SetMaterialProperty("MirrSurface", "REFLECTIVITY", npoints_i, ephoton_i, reflectivity_i); } if(fTakeRealReflectivity == kTRUE){ gMC->SetMaterialProperty("MirrSurface", "REFLECTIVITY", npoints_r, ephoton_r, reflectivity_r); } cout<<"fbarnum = "<barNum() > 1){ gMC->DefineOpSurface("EVSurface", kGlisur, kDielectric_metal, kPolished, 0.0); gMC->SetBorderSurface("EVAirSurface", "DrcEV", 1, "BarrelDIRC", 0, "EVSurface"); gMC->SetMaterialProperty("EVSurface", "REFLECTIVITY", npoints_i, ephoton_i, reflectivity_i); gMC->DefineOpSurface("PDSurface", kGlisur, kDielectric_dielectric, kPolished, 0.0); gMC->SetBorderSurface("EVPDSurface", "DrcEV", 1, "DrcPDSensor", 1, "PDSurface"); gMC->SetMaterialProperty("PDSurface", "EFFICIENCY", npoints_i, ephoton_i, reflectivity_i); } if( fGeo->barNum() == 1 ){ if(fMirrorGap == 0.){ gMC->SetBorderSurface("BarMirrSurface", "DrcBarSensor", 1, "DrcMirr", 1, "MirrSurface"); } if( fGeo->barNum() > 1){ gMC->SetSkinSurface("AirMirrorSurface", "DrcMirr", "MirrSurface"); } //cout<<"bar num = "<BBoxNum()<BBoxNum(); m++){ gMC->DefineOpSurface("EVSurface", kGlisur, kDielectric_metal, kPolished, 0.0); gMC->SetBorderSurface("EVAirSurface", "DrcEV", m, "BarrelDIRC", 0, "EVSurface"); gMC->SetMaterialProperty("EVSurface", "REFLECTIVITY", npoints_i, ephoton_i, reflectivity_i); } } cout<<" ======= DRC::ConstructOpGeometry -> Finished! ====== "<< endl; } // ----- Public method CheckIfSensitive -------------------------------------- bool PndDrc::CheckIfSensitive(std::string name) { for (Int_t i = 0; i < fListOfSensitives.size(); i++){ if (name.find(fListOfSensitives[i]) != std::string::npos) return true; } return false; } // ----- Private method AddHit -------------------------------------------- PndDrcPDPoint* PndDrc::AddHit(Int_t trackID, Int_t copyNo, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Int_t pdgCode, Int_t eventID) { TClonesArray& clrefPD = *fDrcPDCollection; Int_t size = clrefPD.GetEntriesFast(); if (fVerboseLevel>1) cout << "-I- PndDrc: Adding Point at (" << pos.X() << ", " << pos.Y() << ", " << pos.Z() << ") cm, detector " << copyNo << ", track " << trackID <<" event "<1) cout << "-I- PndBarDrc: Adding Point at (" << pos.X() << ", " << pos.Y() << ", " << pos.Z() << ") cm, detector " << copyNo << ", track " << trackID <<" event "<