#include "PndFtsDataAccessor.h" //#include "PndDetectorList.h" #include "PndMCTrack.h" #include "PndTrackCand.h" #include "PndTrack.h" #include "FairTrackParP.h" #include "FairMCPoint.h" #include "FairHit.h" //#include "FairMCApplication.h" #include "FairTask.h" //#include "FairRunAna.h" //#include "FairGeoNode.h" //#include "FairGeoVector.h" //#include "FairGeoMedium.h" #include "FairRootManager.h" #include "TObjectTable.h" #include "TClonesArray.h" #include "TParticlePDG.h" #include "TRandom3.h" #include // fts #include "PndFtsPoint.h" #include "PndFtsHit.h" #include "PndFtsTube.h" #include "PndFtsMapCreator.h" // fairroot #include "FairRootManager.h" #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "FairField.h" #include "TMatrixD.h" #include "TVectorD.h" using namespace std; //________________________________________________________________ PndFtsDataAccessor::PndFtsDataAccessor(): FairTask("FTSDataAccessor"), fMCTracks(0), pdg(0), fPersistence(kTRUE), By(0) { //--- fVerbose = 0; for (int i=0;i<4;i++) fBranchActive[i]=kTRUE; } //_________________________________________________________________ PndFtsDataAccessor::~PndFtsDataAccessor() { FairRootManager *fManager =FairRootManager::Instance(); fManager->Write(); } //_________________________________________________________________ void PndFtsDataAccessor::Register() { //--- if(fVerbose>3) Info("Register","Done."); } void PndFtsDataAccessor::SetParContainers() { FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb(); fFtsParameters = (PndGeoFtsPar*) rtdb->getContainer("PndGeoFtsPar"); } //________________________________________________________________ InitStatus PndFtsDataAccessor::Init() { // --- if(fVerbose>3) Info("Init","Start initialisation."); FairRootManager *fManager = FairRootManager::Instance(); // Get MC arrays fMCTracks = dynamic_cast(fManager->GetObject("MCTrack")); if ( ! fMCTracks ) { std::cout << "-W- PndFtsDataAccessor::Init: No MCTrack array! Needed for MC Truth" << std::endl; return kERROR; } //FTS fMCPoints[0] = dynamic_cast (fManager->GetObject("FTSPoint")); if ( ! fMCPoints[0] ) { std::cout << "-W- PndFtsDataAccessor::Init: No FTSPoint array!" << std::endl; return kERROR; } fHits[0] = dynamic_cast (fManager->GetObject("FTSHit")); if ( ! fHits[0] ) { std::cout << "-W- PndFtsDataAccessor::Init: No FTSHit array!" << std::endl; return kERROR; } fBranchIDs[0] = FairRootManager::Instance()->GetBranchId("FTSHit"); //GEM fMCPoints[1] = dynamic_cast (fManager->GetObject("GEMPoint")); if ( ! fMCPoints[1] ) { std::cout << "-W- PndFtsDataAccessor::Init: No GEMPoint array!" << std::endl; fMCPoints[1]=new TClonesArray("FairMCPoint"); } fHits[1] = dynamic_cast (fManager->GetObject("GEMHit")); if ( ! fHits[1] ) { std::cout << "-W- PndFtsDataAccessor::Init: No GEMHit array!" << std::endl; fHits[1]=new TClonesArray("FairHit"); } fBranchIDs[1] = FairRootManager::Instance()->GetBranchId("GEMHit"); //MVD Pixel fMCPoints[2] = dynamic_cast (fManager->GetObject("MVDPoint")); if ( ! fMCPoints[2] ) { std::cout << "-W- PndFtsDataAccessor::Init: No MVDPoint array!" << std::endl; fMCPoints[1]=new TClonesArray("FairMCPoint"); } fHits[2] = dynamic_cast (fManager->GetObject("MVDHitsPixel")); if ( ! fHits[2] ) { std::cout << "-W- PndFtsDataAccessor::Init: No MVDHitsPixel array!" << std::endl; fHits[2]=new TClonesArray("FairHit"); } fBranchIDs[2] = FairRootManager::Instance()->GetBranchId("MVDHitsPixel"); fMCPoints[3] = fMCPoints[2]; fHits[3] = dynamic_cast (fManager->GetObject("MVDHitsStrip")); if ( ! fHits[3] ) { std::cout << "-W- PndFtsDataAccessor::Init: No MVDHitsStrip array!" << std::endl; fMCPoints[3]=new TClonesArray("FairHit"); } fBranchIDs[3] = FairRootManager::Instance()->GetBranchId("MVDHitsStrip"); if(fVerbose>3) Info("Init","Fetched all arrays."); Register(); pdg = new TDatabasePDG(); if(fVerbose>3) Info("Init","End initialisation."); PndFtsMapCreator *mapperFts = new PndFtsMapCreator(fFtsParameters); fTubeArrayFts = mapperFts->FillTubeArray(); if(fVerbose>3) Info("Init","Try to get B field."); fField = FairRunAna::Instance()->GetField(); By = 0.; po[0] = 0; po[1] = 0; po[2] = 0; fField->GetFieldValue(po, BB); //return value in KG (G3) By = BB[1] / 10.; // By is y-component of magnetic field in Tesla return kSUCCESS; } //_________________________________________________________________ void PndFtsDataAccessor::Exec(Option_t * option) { if(fVerbose>3) Info("Exec","Start eventloop."); if(fVerbose>4){ Info("Exec","Print some array properties"); for(int iii=0;iii<4;iii++){ std::cout<<"fHits["<GetName()<<" and contains "<GetEntriesFast()<<" entries."<GetName()<<" and contains "<GetEntriesFast()<<" entries."<4) Info("Exec","Use detector %i",iDet); std::map firstHit; std::map lastHit; std::map firstPoint; std::map lastPoint; std::map candlist; const int NHits = fHits[iDet]->GetEntriesFast(); // cout << " ----------------------- Store data ------------------------- " << endl; // cout << " NFTSHits = " << NHits << endl; outH << NHits << endl; outHL << NHits << endl; outMCP << NHits << endl; // WARNING: Currently use only MCPoints, which produces hits!!!! map nHitsInMCTrack, nMCPointsInMCTrack, FirstMCPointIDInMCTrack; const int NStations = 48; vector zOfStation(NStations, -1.f); int iWrittenHit = -1; for (Int_t ih = 0; ih < NHits; ih++) { // RecoHits PndFtsHit* hit = (PndFtsHit*) fHits[iDet]->At(ih); if(!hit) { if(fVerbose>3) Error("Exec","Have no ghit %i, array size: %i",ih,fHits[iDet]->GetEntriesFast()); continue; } iWrittenHit++; Int_t tubeID = ((PndFtsHit*) hit)->GetTubeID(); PndFtsTube *tube = (PndFtsTube*) fTubeArrayFts->At(tubeID); TVector3 position = tube->GetPosition(); const Double_t x = position.X(); const Double_t y = position.Y(); const Double_t z = position.Z(); outH << x << " " << y << " " << z << " " << hit->GetIsochrone() << endl; const int iSta = hit->GetLayerID() - 1; if ( zOfStation[iSta] == -1.f) zOfStation[iSta] = z; else if ( std::abs(zOfStation[iSta] - z) > 1e-4f ) // 1mum precision cout << " WARNING: different z positions within one layer. Settings inforation can be corrupted. " << zOfStation[iSta] << " " << z << endl; const Double_t dR = hit->GetIsochroneError(); const Double_t dR2 = dR*dR; const Double_t kSS = 1.5; // coefficient between size and sigma const Double_t dXY = tube->GetRadIn(); const Double_t errXY = dXY/kSS; const Double_t errXY2 = errXY*errXY; const Double_t errZ = tube->GetHalfLength()/kSS*sqrt(26); // 26 rows with basicaly same information TMatrixT RM = tube->GetRotationMatrix(); TMatrixT C(3,3); // CovMatrix C[0][0] = errXY2; C[1][1] = errXY2; C[2][2] = errZ*errZ; C[0][1] = C[0][2] = C[1][0] = C[1][2] = C[2][0] = C[2][1] = 0; TMatrixT CR = C; // rotated CovMatrix CR = RM*C; CR = CR*RM.Transpose(RM); outH << CR[0][0] << " " << CR[0][1] << " " << CR[0][2] << endl; outH << CR[1][0] << " " << CR[1][1] << " " << CR[1][2] << endl; outH << CR[2][0] << " " << CR[2][1] << " " << CR[2][2] << endl; outH << dR2 << endl; outH << tube->GetRadIn() << " " << tube->GetHalfLength() << endl; TVector3 wire_direction = tube->GetWireDirection(); // shows the wire direction, ( notSkewed layers - wire_direction.X() == 1 ). outH << wire_direction.X() << " " << wire_direction.Y() << " " << wire_direction.Z() << endl; // TODO rid of covMatrix outH << iSta << " " << iWrittenHit << " " << -1234 << endl; // station position is normal to z // MC Points Int_t mchitid=hit->GetRefIndex(); if(mchitid<0) { if(fVerbose>3) Error("Exec","Have a negative mcHit %i",mchitid); continue; } const FairMCPoint* point = (FairMCPoint*)(fMCPoints[iDet]->At(mchitid)); if(!point) continue; Int_t trackID = point->GetTrackID(); if(trackID<0) continue; Double_t q = 1; { // get charge const TClonesArray* fMCTrackArray = fMCTracks; if ( trackID < fMCTrackArray->GetEntriesFast() ) { const PndMCTrack* mcTr = (PndMCTrack*) fMCTrackArray->At(trackID); if ( mcTr ) { TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(mcTr->GetPdgCode()); if ( part ) q = part->Charge()/3.f; } else { cout << " Bad MCTracks2" << endl; } } else { cout << " Bad MCTracks" << endl; } } outHL << trackID << " " << -1 << " " << -1 << endl; outMCP << point->GetX() << " " << point->GetY() << " " << point->GetZ() << endl; outMCP << point->GetPx() << " " << point->GetPy() << " " << point->GetPz() << " " << q/sqrt( point->GetPx()*point->GetPx() + point->GetPy()*point->GetPy() + point->GetPz()*point->GetPz() ) << endl; outMCP << 0 << " " << iSta << " " << trackID << " " << trackID << endl; if ( nHitsInMCTrack.find(trackID) != nHitsInMCTrack.end() ) { nHitsInMCTrack[trackID]++; nMCPointsInMCTrack[trackID]++; } else { nHitsInMCTrack[trackID] = 1; nMCPointsInMCTrack[trackID] = 1; FirstMCPointIDInMCTrack[trackID] = iWrittenHit; } } // end loop over hits { // MC Tracks const TClonesArray* fMCTrackArray = fMCTracks; const int nMCTracks = fMCTrackArray->GetEntriesFast(); outMCT << nMCTracks << endl; for ( int i = 0; i < nMCTracks; i++ ){ const PndMCTrack* mcTr = (PndMCTrack*) fMCTrackArray->At(i); if ( !mcTr ) { outMCT << -1 << " " << -1 << endl; outMCT << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << endl; outMCT << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << endl; outMCT << 0 << " " << 0 << endl; outMCT << 0 << " " << 0 << " " << 0 << endl; outMCT << 0 << " " << 0 << " " << 1 << endl; } else { Int_t pdgCode = mcTr->GetPdgCode(); Double_t px = mcTr->GetMomentum().X(); Double_t py = mcTr->GetMomentum().Y(); Double_t pz = mcTr->GetMomentum().Z(); Double_t p = sqrt( px*px + py*py + pz*pz ); Double_t q = 1; { // get charge TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(pdgCode); if ( part ) q = part->Charge()/3.f; } Double_t ex,ey,ez,qp; outMCT << mcTr->GetMotherID() << " " << pdgCode << endl; outMCT << mcTr->GetStartVertex().X() << " " << mcTr->GetStartVertex().Y() << " " << mcTr->GetStartVertex().Z() << " " << px/fabs(p) << " " << py/fabs(p) << " " << pz/fabs(p) << " " << q/p << endl; outMCT << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << endl; outMCT << p << " " << sqrt( px*px + py*py ) << endl; outMCT << nHitsInMCTrack[i] << " " << nMCPointsInMCTrack[i] << " " << FirstMCPointIDInMCTrack[i] << endl; outMCT << 0 << " " << 0 << " " << 1 << endl; } } } // Settings static bool isFirstEvent = true; if ( isFirstEvent ) { isFirstEvent = false; TString fadataGeo_name = folder_name + "settings.data"; fstream outGeo(fadataGeo_name, fstream::out); outGeo << NStations << endl; outGeo << -10 << endl; // field for( int iS = 0; iS < NStations; iS++ ) { float slope = 5.f/180.f*3.14159265359f; switch ( (iS/2)%4 ) { case 0: slope = 0; break; case 1: slope = slope; break; case 2: slope = -slope; break; case 3: slope = 0; break; } outGeo << iS << " " << zOfStation[iS] << " " << 0.00044 << " " << 0.0117 << " " << slope << " " << 1 << " " << 6 << endl; } const int NSubStations = 8; const float Height[NStations/NSubStations] = { 640, 640, 741.9, 818.9, 1200.0, 1200.0 }; // mm float YMin[NStations/NSubStations]; // filled later float YMax[NStations/NSubStations]; // filled later float XMin[NStations/NSubStations] = { -659.025, -659.025, -881.225, -1042.825, -1951.825, -1951.825 }; // mm float XMax[NStations/NSubStations]; // filled later const float NTubes[NStations/NSubStations] = { 132, 132, 176, 208, 388, 388 }; float Z[NStations] = { 2949.627, 2958.373, 2999.627, 3008.373, 3049.627, 3058.373, 3099.627, 3108.373, // mm 3269.627, 3278.373, 3319.627, 3328.373, 3369.627, 3378.373, 3419.627, 3428.373, 3940.627, 3949.373, 4015.377, 4024.123, 4160.627, 4169.373, 4235.377, 4244.123, 4380.627, 4389.373, 4455.377, 4464.123, 4600.627, 4609.373, 4675.377, 4684.123, 6070.627, 6079.373, 6120.627, 6129.373, 6170.627, 6179.373, 6220.627, 6229.373, 6390.627, 6399.373, 6440.627, 6449.373, 6490.627, 6499.373, 6540.627, 6549.373 }; for( int i = 0; i < NStations/NSubStations; i++ ) { XMax[i] = XMin[i] + NTubes[i]*10.1; YMin[i] = -Height[i]/2; YMax[i] = Height[i]/2; // convert into cm XMin[i] /= 10; XMax[i] /= 10; YMin[i] /= 10; YMax[i] /= 10; } for( int i = 0; i < NStations; i++ ) { Z[i] /= 10; } // Field int ind = 0; for( int i=0; i<3; i++ ){ Double_t z = i*(Z[0]-1.f)/2; // last point is taken in 1 cm from first station Double_t point[3] = {0,0,z}; Double_t B[3] = {0,0,0}; fField->GetFieldValue( point, B ); outGeo << z << " " << B[0] << " " << B[1] << " " << B[2] << endl; } const int M=5; // polinom order const int N=(M+1)*(M+2)/2; const int MaxN = 100; for ( Int_t ist = 0; ist DX/N/4 ) dx = DX/N/4.; if( dy > DY/N/2 ) dy = DY/N/4.; double C[3][MaxN] = {0}; for( int i=0; i<3; i++) for( int k=0; k 0 && ist%NSubStations == 0) ? static_cast((Z[ist] - Z[ist-1])/dzVirtualStations) : 0; outGeo << ist << endl; outGeo << nVirtualStations << " " << dzVirtualStations << endl; outGeo << XMinS << " " << dx << " " << NXBins << endl; outGeo << YMinS << " " << dy << " " << NYBins << endl; for( int iV = nVirtualStations; iV >= 0; iV-- ) for( double ixb = 0; ixb < NXBins; ixb++ ) { for( double iyb = 0; iyb < NYBins; iyb++ ) { const double x = XMinS + ixb*dx; const double y = YMinS + iyb*dy; Double_t p[3] = {x, y, ZS - iV*dzVirtualStations}; Double_t B[3] = {0.,0.,0.}; fField->GetFieldValue(p, B); // outGeo << B[0] << " " << B[1] << " " << B[2] << endl; double r = sqrt( (x - XAverage)*(x - XAverage)/DX/DX + (y - YAverage)*(y - YAverage)/DY/DY ); // if( r>1. ) continue; Double_t w = 1./(r*r+1); TVectorD m(N); m(0)=1; for( int i=1; i<=M; i++){ int k = (i-1)*(i)/2; int l = i*(i+1)/2; for( int j=0; jGetFieldValue(p, B); Double_t r = (B[0] - BA[0])*(B[0] - BA[0]) + (B[1] - BA[1])*(B[1] - BA[1]) + (B[2] - BA[2])*(B[2] - BA[2]); r = sqrt(r); N++; sumR += r; // if( r < 0.005 ) { cout << r << " " << x << " " << y << " " << B[0] << " " << B[1] << " " << B[2] << " " << BA[0] << " " << BA[1] << " " << BA[2] << endl; exit(0); } } // cout << ist << " AVR R = " << sumR/N << endl; #endif } outGeo.close(); } // settings } // iDet outH.close(); outHL.close(); outMCT.close(); outMCP.close(); if(fVerbose>3) Info("Exec","End eventloop."); } ClassImp(PndFtsDataAccessor);