8 #include "FairTrackParP.h" 
    9 #include "FairMCPoint.h" 
   17 #include "FairRootManager.h" 
   19 #include "TObjectTable.h" 
   20 #include "TClonesArray.h" 
   21 #include "TParticlePDG.h" 
   31 #include "FairRootManager.h" 
   32 #include "FairRunAna.h" 
   33 #include "FairRuntimeDb.h" 
   35 #include "FairField.h" 
   42   FairTask(
"FTSDataAccessor"), fMCTracks(0), By(0), fPersistence(kTRUE), pdg(0)
 
   52   FairRootManager *fManager =FairRootManager::Instance();
 
   60   if(
fVerbose>3) Info(
"Register",
"Done.");
 
   65   FairRuntimeDb* 
rtdb = FairRunAna::Instance()->GetRuntimeDb();
 
   72   if(
fVerbose>3) Info(
"Init",
"Start initialisation.");
 
   74   FairRootManager *fManager = FairRootManager::Instance();
 
   77   fMCTracks = 
dynamic_cast<TClonesArray *
>(fManager->GetObject(
"MCTrack"));
 
   79     std::cout << 
"-W-  PndFtsDataAccessor::Init: No MCTrack array! Needed for MC Truth" << std::endl;
 
   84   fMCPoints[0] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"FTSPoint"));
 
   86     std::cout << 
"-W-  PndFtsDataAccessor::Init: No FTSPoint array!" << std::endl;
 
   89   fHits[0] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"FTSHit"));
 
   91     std::cout << 
"-W-  PndFtsDataAccessor::Init: No FTSHit array!" << std::endl;
 
   94   fBranchIDs[0] =       FairRootManager::Instance()->GetBranchId(
"FTSHit");
 
   98   fMCPoints[1] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"GEMPoint"));
 
  100     std::cout << 
"-W-  PndFtsDataAccessor::Init: No GEMPoint array!" << std::endl;
 
  101     fMCPoints[1]=
new TClonesArray(
"FairMCPoint");
 
  103   fHits[1] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"GEMHit"));
 
  105     std::cout << 
"-W-  PndFtsDataAccessor::Init: No GEMHit array!" << std::endl;
 
  106     fHits[1]=
new TClonesArray(
"FairHit");
 
  108   fBranchIDs[1] =       FairRootManager::Instance()->GetBranchId(
"GEMHit");
 
  111   fMCPoints[2] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"MVDPoint"));
 
  113     std::cout << 
"-W-  PndFtsDataAccessor::Init: No MVDPoint array!" << std::endl;
 
  114     fMCPoints[1]=
new TClonesArray(
"FairMCPoint");
 
  116   fHits[2] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"MVDHitsPixel"));
 
  118     std::cout << 
"-W-  PndFtsDataAccessor::Init: No MVDHitsPixel array!" << std::endl;
 
  119     fHits[2]=
new TClonesArray(
"FairHit");
 
  121   fBranchIDs[2] =       FairRootManager::Instance()->GetBranchId(
"MVDHitsPixel");
 
  124   fHits[3] = 
dynamic_cast<TClonesArray *
> (fManager->GetObject(
"MVDHitsStrip"));
 
  126     std::cout << 
"-W-  PndFtsDataAccessor::Init: No MVDHitsStrip array!" << std::endl;
 
  127     fMCPoints[3]=
new TClonesArray(
"FairHit");
 
  129   fBranchIDs[3] =       FairRootManager::Instance()->GetBranchId(
"MVDHitsStrip");
 
  131   if(
fVerbose>3) Info(
"Init",
"Fetched all arrays.");
 
  135   pdg = 
new TDatabasePDG();
 
  136   if(
fVerbose>3) Info(
"Init",
"End initialisation.");
 
  144   if(
fVerbose>3) Info(
"Init",
"Try to get B field.");
 
  145   fField = FairRunAna::Instance()->GetField();
 
  161   if(
fVerbose>3) Info(
"Exec",
"Start eventloop.");
 
  163     Info(
"Exec",
"Print some array properties");
 
  164     for(
int iii=0;iii<4;iii++){
 
  165       std::cout<<
"fHits["<<iii<<
"] is branchID "<<
fBranchIDs[iii]<<
" with the name "<<
fHits[iii]->GetName()<<
" and contains "<<
fHits[iii]->GetEntriesFast()<<
" entries."<<std::endl;
 
  166       std::cout<<
"fMCPoints["<<iii<<
"] with the name "<<
fMCPoints[iii]->GetName()<<
" and contains "<<
fMCPoints[iii]->GetEntriesFast()<<
" entries."<<std::endl;
 
  171   static int iEvent = -1;
 
  174   TString fadata_name = 
"data/event";
 
  175   fadata_name += iEvent;
 
  176   TString fadataH_name = fadata_name + 
"_hits.data";
 
  177   TString fadataHL_name = fadata_name + 
"_hitLabels.data";
 
  178   TString fadataMCT_name = fadata_name + 
"_MCTracks.data";
 
  179   TString fadataMCP_name = fadata_name + 
"_MCPoints.data";
 
  190   for(Int_t iDet=0;iDet<1;iDet++) { 
 
  193     if(
fVerbose>4) Info(
"Exec",
"Use detector %i",iDet);
 
  195     std::map<Int_t, FairHit*> firstHit;
 
  196     std::map<Int_t, FairHit*> lastHit;
 
  197     std::map<Int_t, FairMCPoint*> firstPoint;
 
  198     std::map<Int_t, FairMCPoint*> lastPoint;
 
  199     std::map<Int_t, PndTrackCand*> candlist;
 
  201     const int NHits = 
fHits[iDet]->GetEntriesFast();
 
  204     outH << NHits << endl;
 
  205     outHL << NHits << endl;
 
  206     outMCP << NHits << endl; 
 
  207     map<int, unsigned int> nHitsInMCTrack, nMCPointsInMCTrack, FirstMCPointIDInMCTrack;
 
  208     const int NStations = 48;
 
  209     vector<float> zOfStation(NStations, -1.
f);
 
  210     int iWrittenHit = -1;
 
  211     for (Int_t ih = 0; ih < NHits; ih++) {
 
  221       Int_t tubeID = ((
PndFtsHit*) hit)->GetTubeID();
 
  227       outH << x << 
" " << y << 
" " << z << 
" " << hit->
GetIsochrone() << endl;
 
  230       if ( zOfStation[iSta] == -1.
f)
 
  231         zOfStation[iSta] = 
z;
 
  233         if ( std::abs(zOfStation[iSta] - z) > 1e-4
f ) 
 
  234           cout << 
" WARNING: different z positions within one layer. Settings inforation can be corrupted. " << zOfStation[iSta] << 
" " << z << endl;
 
  241       const Double_t errXY2 = errXY*errXY;
 
  245       TMatrixT<Double_t> 
C(3,3); 
 
  249       C[0][1] = C[0][2] = C[1][0] = C[1][2] = C[2][0] = C[2][1] = 0;
 
  251       TMatrixT<Double_t> 
CR = 
C; 
 
  254       CR = CR*RM.Transpose(RM);
 
  255       outH << CR[0][0] << 
" " << CR[0][1] << 
" " << CR[0][2] << endl;
 
  256       outH << CR[1][0] << 
" " << CR[1][1] << 
" " << CR[1][2] << endl;
 
  257       outH << CR[2][0] << 
" " << CR[2][1] << 
" " << CR[2][2] << endl;
 
  262       outH << wire_direction.X() << 
" "  << wire_direction.Y() << 
" "  << wire_direction.Z() << endl; 
 
  263       outH << iSta << 
" " << iWrittenHit << 
" " << -1234 << endl; 
 
  266       Int_t mchitid=hit->GetRefIndex();
 
  268         if(
fVerbose>3) Error(
"Exec",
"Have a negative mcHit %i",mchitid);
 
  273       Int_t trackID = point->GetTrackID();
 
  274       if(trackID<0) 
continue;
 
  278         const TClonesArray* fMCTrackArray = 
fMCTracks;
 
  282             TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(mcTr->
GetPdgCode());
 
  284               q = part->Charge()/3.f;
 
  286           else { cout << 
" Bad MCTracks2" << endl; }
 
  288         else { cout << 
" Bad MCTracks" << endl; }
 
  291       outHL << trackID << 
" " << -1 << 
" " << -1 << endl;
 
  292       outMCP << point->GetX() << 
" " << point->GetY() << 
" " << point->GetZ() << endl;
 
  293       outMCP << point->GetPx() << 
" " << point->GetPy() << 
" " << point->GetPz() << 
" " 
  294              << q/
sqrt( point->GetPx()*point->GetPx() + point->GetPy()*point->GetPy() + point->GetPz()*point->GetPz() ) << endl;
 
  295       outMCP << 0 << 
" " << iSta << 
" " << trackID << 
" " << trackID << endl;
 
  297       if ( nHitsInMCTrack.find(trackID) != nHitsInMCTrack.end() ) {
 
  298         nHitsInMCTrack[trackID]++;
 
  299         nMCPointsInMCTrack[trackID]++;
 
  301         nHitsInMCTrack[trackID] = 1;
 
  302         nMCPointsInMCTrack[trackID] = 1;
 
  303         FirstMCPointIDInMCTrack[trackID] = iWrittenHit;
 
  309       const TClonesArray* fMCTrackArray = 
fMCTracks;
 
  310       const int nMCTracks = fMCTrackArray->GetEntriesFast();
 
  312       outMCT << nMCTracks << endl;
 
  313       for ( 
int i = 0; 
i < nMCTracks; 
i++ ){
 
  317           outMCT << -1 << 
" " << -1 << endl;
 
  318           outMCT << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << endl;
 
  319           outMCT << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << endl;
 
  320           outMCT << 0 << 
" " << 0 << endl;
 
  321           outMCT << 0 << 
" " << 0 << 
" " << 0 << endl;
 
  322           outMCT << 0 << 
" " << 0 << 
" " << 1 << endl;
 
  333             TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(pdgCode);
 
  335               q = part->Charge()/3.f;
 
  338           outMCT << mcTr->
GetMotherID() << 
" " << pdgCode << endl;
 
  340                  << px/
fabs(p) << 
" " << py/
fabs(p) << 
" " << pz/
fabs(p) << 
" " << q/p << endl;
 
  341           outMCT << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << 
" " << 0 << endl;
 
  342           outMCT << p << 
" " << 
sqrt( px*px + py*py ) << endl;
 
  343           outMCT << nHitsInMCTrack[
i] << 
" " << nMCPointsInMCTrack[
i] << 
" " << FirstMCPointIDInMCTrack[
i] << endl;
 
  344           outMCT << 0 << 
" " << 0 << 
" " << 1 << endl;
 
  351     static bool isFirstEvent = 
true;
 
  352     if ( isFirstEvent ) {
 
  353       isFirstEvent = 
false;
 
  355       TString fadataGeo_name = folder_name + 
"settings.data";
 
  358       outGeo << NStations << endl;
 
  359       outGeo << -10 << endl; 
 
  360       for( 
int iS = 0; iS < NStations; iS++ ) {
 
  361         float slope = 5.f/180.f*3.14159265359f;
 
  362         switch ( (iS/2)%4 ) {
 
  363           case 0: slope = 0; 
break;
 
  364           case 1: slope =  slope; 
break;
 
  365           case 2: slope = -slope; 
break;
 
  366           case 3: slope = 0; 
break;
 
  368         outGeo << iS << 
" " << zOfStation[iS] << 
" " << 0.00044 << 
" " << 0.0117 << 
" " << slope << 
" " << 1 << 
" " << 6 << endl;
 
  371       const int NSubStations = 8;
 
  372       const float Height[NStations/NSubStations] = { 640, 640, 741.9, 818.9, 1200.0, 1200.0 }; 
 
  373       float YMin[NStations/NSubStations]; 
 
  374       float YMax[NStations/NSubStations]; 
 
  375       float XMin[NStations/NSubStations]   = { -659.025, -659.025, -881.225, -1042.825, -1951.825, -1951.825 }; 
 
  376       float XMax[NStations/NSubStations]; 
 
  377       const float NTubes[NStations/NSubStations] = { 132,      132,      176,      208,       388,       388       };
 
  378       float Z[NStations]   = { 2949.627, 2958.373, 2999.627, 3008.373, 3049.627, 3058.373, 3099.627, 3108.373,  
 
  379                                3269.627, 3278.373, 3319.627, 3328.373, 3369.627, 3378.373, 3419.627, 3428.373,
 
  380                                3940.627, 3949.373, 4015.377, 4024.123, 4160.627, 4169.373, 4235.377, 4244.123,
 
  381                                4380.627, 4389.373, 4455.377, 4464.123, 4600.627, 4609.373, 4675.377, 4684.123,
 
  382                                6070.627, 6079.373, 6120.627, 6129.373, 6170.627, 6179.373, 6220.627, 6229.373,
 
  383                                6390.627, 6399.373, 6440.627, 6449.373, 6490.627, 6499.373, 6540.627, 6549.373 };
 
  385       for( 
int i = 0; 
i < NStations/NSubStations; 
i++ ) {
 
  386         XMax[
i] = XMin[
i]  + NTubes[
i]*10.1;
 
  387         YMin[
i] = -Height[
i]/2;
 
  388         YMax[
i] =  Height[
i]/2;
 
  395       for( 
int i = 0; 
i < NStations; 
i++ ) {
 
  401       for( 
int i=0; 
i<3; 
i++ ){
 
  405         fField->GetFieldValue( point, B );
 
  406         outGeo << z << 
" " << B[0] << 
" " << B[1] << 
" " << B[2] << endl;
 
  410       const int N=(M+1)*(M+2)/2;
 
  411       const int MaxN = 100;
 
  413       for ( Int_t ist = 0; ist<NStations; ist++ ) {
 
  414         const float XMinS = XMin[ist/8]/2;
 
  415         const float XMaxS = XMax[ist/8]/2;
 
  416         const float YMinS = YMin[ist/8]/2;
 
  417         const float YMaxS = YMax[ist/8]/2;
 
  418         const float ZS = Z[ist];
 
  419         const float DX = XMaxS - XMinS;
 
  420         const float DY = YMaxS - YMinS;
 
  421         const float XAverage = XMaxS - XMinS;
 
  422         const float YAverage = YMaxS - YMinS;
 
  428         if( dx > DX/N/4 ) dx = DX/N/4.;
 
  429         if( dy > DY/N/2 ) dy = DY/N/4.;
 
  431         double C[3][MaxN] = {0};
 
  432         for( 
int i=0; 
i<3; 
i++)
 
  433           for( 
int k=0; k<MaxN; k++) C[
i][k] = 0;
 
  436         TVectorD b0(N), 
b1(N), 
b2(N);
 
  437         for( 
int i=0; 
i<N; 
i++){
 
  438           for( 
int j=0; j<N; j++) A(
i,j) = 0.;
 
  442         const int NXBins = (XMaxS - XMinS)/dx;
 
  443         const int NYBins = (YMaxS - YMinS)/dy;
 
  444         const float dzVirtualStations = 5.f;
 
  445         int nVirtualStations = (ist > 0 && ist%NSubStations == 0) ? static_cast<int>((Z[ist] - Z[ist-1])/dzVirtualStations) : 0;
 
  446         outGeo << ist << endl;
 
  447         outGeo << nVirtualStations << 
" " << dzVirtualStations << endl;
 
  448         outGeo << XMinS << 
" " << dx << 
" " << NXBins << endl;
 
  449         outGeo << YMinS << 
" " << dy << 
" " << NYBins << endl;
 
  451         for( 
int iV = nVirtualStations; iV >= 0;  iV-- )
 
  452         for( 
double ixb = 0; ixb < NXBins; ixb++ ) {
 
  453           for( 
double iyb = 0; iyb < NYBins; iyb++ ) {
 
  454             const double x = XMinS + ixb*
dx;
 
  455             const double y = YMinS + iyb*
dy;
 
  459             fField->GetFieldValue(p, B);
 
  461             double r = 
sqrt( (x - XAverage)*(x - XAverage)/DX/DX +
 
  462                              (y - YAverage)*(y - YAverage)/DY/DY  );
 
  468             for( 
int i=1; 
i<=M; 
i++){
 
  471               for( 
int j=0; j<
i; j++ ) 
m(l+j) = x*
m(k+j);
 
  476             for( 
int i=0; 
i<N; 
i++){
 
  477               for( 
int j=0; j<N;j++) A(
i,j)+=w*
m(
i)*
m(j);
 
  486         TVectorD c0 = A*b0, 
c1 = A*
b1, 
c2 = A*
b2;
 
  487         for(
int i=0; 
i<N; 
i++){
 
  494         for( 
int k=0; k<3; k++ ){
 
  495           for( 
int j=0; j<N; j++)
 
  496             outGeo << C[k][j] << 
" ";
 
  504         for( 
double x = XMinS; 
x <= XMaxS; 
x += dx/10 )
 
  505           for( 
double y = YMinS; 
y <= YMaxS; 
y += dy/10 ) {
 
  546             BA[0] = C[0][0] +C[0][1]*x +C[0][2]*y +C[0][3]*x2 +C[0][4]*xy +C[0][5]*y2 +C[0][6]*x3 +C[0][7]*x2y +C[0][8]*xy2 +C[0][9]*y3
 
  547               +C[0][10]*x4 +C[0][11]*x3y +C[0][12]*x2y2 +C[0][13]*xy3 +C[0][14]*y4
 
  548               +C[0][15]*x5 +C[0][16]*x4y +C[0][17]*x3y2 +C[0][18]*x2y3 +C[0][19]*xy4 +C[0][20]*y5
 
  549               +C[0][21]*x6 +C[0][22]*x5y +C[0][23]*x4y2 +C[0][24]*x3y3 +C[0][25]*x2y4 +C[0][26]*xy5 +C[0][27]*y6
 
  550               +C[0][28]*x7 +C[0][29]*x6y +C[0][30]*x5y2 +C[0][31]*x4y3 +C[0][32]*x3y4 +C[0][33]*x2y5 +C[0][34]*xy6 + C[0][35]*y7;
 
  552             BA[1] = C[1][0] +C[1][1]*x +C[1][2]*y +C[1][3]*x2 +C[1][4]*xy +C[1][5]*y2 +C[1][6]*x3 +C[1][7]*x2y +C[1][8]*xy2 +C[1][9]*y3
 
  553               +C[1][10]*x4 +C[1][11]*x3y +C[1][12]*x2y2 +C[1][13]*xy3 +C[1][14]*y4
 
  554               +C[1][15]*x5 +C[1][16]*x4y +C[1][17]*x3y2 +C[1][18]*x2y3 +C[1][19]*xy4 +C[1][20]*y5
 
  555               +C[1][21]*x6 +C[1][22]*x5y +C[1][23]*x4y2 +C[1][24]*x3y3 +C[1][25]*x2y4 +C[1][26]*xy5 +C[1][27]*y6
 
  556               +C[1][28]*x7 +C[1][29]*x6y +C[1][30]*x5y2 +C[1][31]*x4y3 +C[1][32]*x3y4 +C[1][33]*x2y5 +C[1][34]*xy6 + C[1][35]*y7;
 
  558             BA[2] = C[2][0] +C[2][1]*x +C[2][2]*y +C[2][3]*x2 +C[2][4]*xy +C[2][5]*y2 +C[2][6]*x3 +C[2][7]*x2y +C[2][8]*xy2 +C[2][9]*y3
 
  559               +C[2][10]*x4 +C[2][11]*x3y +C[2][12]*x2y2 +C[2][13]*xy3 +C[2][14]*y4
 
  560               +C[2][15]*x5 +C[2][16]*x4y +C[2][17]*x3y2 +C[2][18]*x2y3 +C[2][19]*xy4 +C[2][20]*y5
 
  561               +C[2][21]*x6 +C[2][22]*x5y +C[2][23]*x4y2 +C[2][24]*x3y3 +C[2][25]*x2y4 +C[2][26]*xy5 +C[2][27]*y6
 
  562               +C[2][28]*x7 +C[2][29]*x6y +C[2][30]*x5y2 +C[2][31]*x4y3 +C[2][32]*x3y4 +C[2][33]*x2y5 +C[2][34]*xy6 + C[2][35]*y7;
 
  566             fField->GetFieldValue(p, B);
 
  567             Double_t r = (B[0] - BA[0])*(B[0] - BA[0]) +
 
  568               (B[1] - BA[1])*(B[1] - BA[1]) +
 
  569               (B[2] - BA[2])*(B[2] - BA[2]);
 
  593   if(
fVerbose>3) Info(
"Exec",
"End eventloop.");
 
friend F32vec4 sqrt(const F32vec4 &a)
PndGeoFtsPar * fFtsParameters
Particle DB. 
virtual ~PndFtsDataAccessor()
FairField * fField
Array of Branch Activeness. 
TVector3 GetMomentum() const 
cout<< "POINTs for new FwEndCap == "<< tsim-> GetEntriesFast()
TClonesArray * fMCPoints[4]
Array of PndMCTrack. 
TVector3 GetWireDirection() const 
Bool_t fBranchActive[4]
Array of Branch IDs. 
TMatrixT< Double_t > GetRotationMatrix() const 
friend F32vec4 fabs(const F32vec4 &a)
TVector3 GetPosition() const 
TClonesArray * fHits[4]
Array of event's points. 
Double_t GetHalfLength() const 
Double_t GetIsochrone() const 
Double_t GetRadIn() const 
TClonesArray * fTubeArrayFts
Double_t GetIsochroneError() const 
virtual void Exec(Option_t *option)
virtual InitStatus Init()
TClonesArray * FillTubeArray()
this function will be used in PndFtsHitProducesRealFast 
TVector3 GetStartVertex() const 
Int_t GetMotherID() const 
cout<<"the Event No is "<< i<< endl;{{if(hit_array->GetEntriesFast()!=mc_array->GetEntriesFast()) continue;PndSdsHit *hit=(PndSdsHit *) hit_array-> At(j)
TMatrixT< double > TMatrixD
Int_t fBranchIDs[4]
Array of event's hits.