21 #include "FairRootManager.h" 
   22 #include "FairRunAna.h" 
   23 #include "FairRuntimeDb.h" 
   25 #include "TGeoManager.h" 
   26 #include "TClonesArray.h" 
   27 #include "TGeoVolume.h" 
   69   hx = 
new TH1F(
"hx", 
"x: mc - reco", 100, -1, 1);
 
   70   hy = 
new TH1F(
"hy", 
"y: mc - reco", 100, -1, 1);
 
   71   hz = 
new TH1F(
"hz", 
"z: mc - reco", 100, -3, 3);
 
   73   hxs = 
new TH1F(
"hxs", 
"x: mc - reco", 100, -1, 1);
 
   74   hys = 
new TH1F(
"hys", 
"y: mc - reco", 100, -1, 1);
 
   75   hzs = 
new TH1F(
"hzs", 
"z: mc - reco", 100, -3, 3);
 
   77   hzresvsslope = 
new TH2F(
"hzresvsslope", 
"z: mc - reco vs slope", 100, -3.5, 3.5, 100, -3., 3.);
 
   80   FairRootManager* ioman = FairRootManager::Instance();
 
   82     cout << 
"-E- PndSttHelixHitProducer::Init: " 
   83          << 
"RootManager not instantiated!" << endl;
 
   88   fTrackArray  = (TClonesArray*) ioman->GetObject(
"STTTrack"); 
 
   91       cout << 
"-E- CbmSttFitTracks::Init: No SttTrack array!" 
  100       cout << 
"-E- CbmSttFitTracks::Init: No SttTrack Cand  array!" 
  106   fPointArray = (TClonesArray*) ioman->GetObject(
"STTPoint");
 
  108     cout << 
"-W- PndSttHelixHitProducer::Init: " 
  109          << 
"No STTPoint array!" << endl;
 
  114   fHitArray = (TClonesArray*) ioman->GetObject(
"STTHit");
 
  116     cout << 
"-W- PndSttHelixHitProducer::Init: " 
  117          << 
"No STTHit array!" << endl;
 
  129   cout << 
"-I- PndSttHelixHitProducer: Intialization successfull" << endl;
 
  138   FairRuntimeDb* 
rtdb = FairRunAna::Instance()->GetRuntimeDb();
 
  155   if ( ! 
fTrackArray ) Fatal(
"Exec", 
"No fTrackArray");
 
  161   for (Int_t j = 0; j < nTracks; j++) {
 
  163     if(!pTrack) 
continue;
 
  166     if(!pTrackCand) 
continue;
 
  179     TVector2 
vec((d0+Rad)*
cos(phi0), (d0+Rad)*
sin(phi0));
 
  182     Int_t hitcounter = pTrackCand->
GetNHits();
 
  183     Int_t hotcounter = 0;
 
  188     for (Int_t k = 0; k < hitcounter; k++) {
 
  192       if(!currenthit) { cout << 
"PndSttHelixHitProducer::Exec: no hit at " << iHit << endl;  
continue; }
 
  198       Int_t refindex = currenthit->GetRefIndex(); 
 
  202         if(!iPoint) { cout << 
"PndSttHelixHitProducer::Exec: no point at " << refindex << 
" associated to hit " << iHit << endl;  
continue; }
 
  208       Int_t size = clref.GetEntriesFast();
 
  213       TVector3 posErr(0, 0, 0);
 
  214       helixhit = 
new(clref[size]) 
PndSttHelixHit(currenthit->GetDetectorID(),  tubeID, iHit, refindex, 
 
  233       if(wiredirection == TVector3(0.,0.,1.)) 
 
  249           Double_t m = (point.Y() - vec.Y())/(point.X() - vec.X());
 
  250           Double_t q = point.Y() - m*point.X();
 
  270           Double_t x1 = (-(m*(q - point.Y()) - point.X()) + 
sqrt(
fabs((m*(q - point.Y()) - point.X())*(m*(q - point.Y()) - point.X()) - (m*m + 1)*((q - point.Y())*(q - point.Y()) + point.X()*point.X() - radius*radius)))) / (m*m + 1);
 
  273           Double_t x2 = (-(m*(q - point.Y()) - point.X()) - 
sqrt(
fabs((m*(q - point.Y()) - point.X())*(m*(q - point.Y()) - point.X()) - (m*m + 1)*((q - point.Y())*(q - point.Y()) + point.X()*point.X() - radius*radius)))) / (m*m + 1);
 
  278           Double_t xb1 = (-(m*(q - vec.Y()) - vec.X()) + 
sqrt(
fabs((m*(q - vec.Y()) - vec.X())*(m*(q - vec.Y()) - vec.X()) - (m*m + 1)*((q - vec.Y())*(q - vec.Y()) + vec.X()*vec.X() - (pTrack->
GetRad()) *(pTrack->
GetRad()))))) / (m*m + 1);
 
  281           Double_t xb2 = (-(m*(q - vec.Y()) - vec.X()) - 
sqrt(
fabs((m*(q - vec.Y()) - vec.X())*(m*(q - vec.Y()) - vec.X()) - (m*m + 1)*((q - vec.Y())*(q - vec.Y()) + vec.X()*vec.X() - (pTrack->
GetRad()) *(pTrack->
GetRad()))))) / (m*m + 1);
 
  285           Double_t distb1 = 
sqrt((yb1 - point.Y())*(yb1 - point.Y()) + (xb1 - point.X())*(xb1 - point.X()));
 
  286           Double_t distb2 = 
sqrt((yb2 - point.Y())*(yb2 - point.Y()) + (xb2 - point.X())*(xb2 - point.X()));
 
  290           if(distb1 > distb2) xyb.Set(xb2, yb2); 
 
  291           else xyb.Set(xb1, yb1); 
 
  294           Double_t dist1 = 
sqrt((xyb.Y() - y1)*(xyb.Y() - y1) + (xyb.X() - x1)*(xyb.X() - x1));
 
  295           Double_t dist2 = 
sqrt((xyb.Y() - y2)*(xyb.Y() - y2) + (xyb.X() - x2)*(xyb.X() - x2));
 
  299           if(dist1 > dist2) xy = 
new TVector2(x2, y2);
 
  300           else xy = 
new TVector2(x1, y1);   
 
  303           helixhit->SetX(xy->X());
 
  304           helixhit->SetY(xy->Y());
 
  310           Double_t zcoord = z0 + zslope * scosl;
 
  311           helixhit->SetZ(zcoord);
 
  314           hx->Fill(iPoint->GetX() - helixhit->GetX());
 
  315           hy->Fill(iPoint->GetY() - helixhit->GetY());
 
  316           hz->Fill(iPoint->GetZ() - helixhit->GetZ());
 
  339             TVector3 *tofit, *tofit2;
 
  345             min = cenposition - wiredirection;
 
  346             max = cenposition + wiredirection;
 
  376             if(
fabs(x_2-x_1)>0.0001) {
 
  377               a =(y_2-y_1)/(x_2-x_1);
 
  381               Double_t C = vec.X()*vec.X()+vec.Y()*vec.Y()+b*b-Rad*Rad-2*vec.Y()*
b;
 
  389             else if(
fabs(y_2-y_1)>0.0001) {
 
  392               Double_t C = vec.Y()*vec.Y() +(x_1-vec.X())*(x_1-vec.X()) -Rad*Rad;
 
  401               if(
fVerbose == 2) cout << 
"-E- intersection point not found" << endl;
 
  407                                     (y1-cenposition.Y())*(y1-cenposition.Y()));
 
  409                                     (y2-cenposition.Y())*(y2-cenposition.Y()));
 
  415             if(d2<d1) {x_=x2;y_=y2;}    
 
  437               Double_t C = x_*x_+ y_*y_+b*b-2*b*y_-radius*radius;
 
  444               else if((B*B-A*C)==0){          
 
  451                 if(
fVerbose == 2) cout << 
"NO WAY2" << endl;
 
  456             d1=
TMath::Sqrt((x1-cenposition.X())*(x1-cenposition.X())+(y1-cenposition.Y())*(y1-cenposition.Y()));
 
  457             d2=
TMath::Sqrt((x2-cenposition.X())*(x2-cenposition.X())+(y2-cenposition.Y())*(y2-cenposition.Y()));
 
  474             if(
fabs(x_2-x_1)<0.001) {
 
  475               t_    =(ycen0-y_1)/(y_2-y_1); 
 
  476               z_    =(z_2-z_1)*t_ +z_1;     
 
  477               t_bis =(ycen1-y_1)/(y_2-y_1); 
 
  478               z_bis =(z_2-z_1)*t_bis +z_1;  
 
  481               t_    =(xcen0-x_1)/(x_2-x_1); 
 
  482               z_    =(z_2-z_1)*t_ +z_1;     
 
  483               t_bis =(xcen1-x_1)/(x_2-x_1); 
 
  484               z_bis =(z_2-z_1)*t_bis +z_1;  
 
  488             tofit = 
new TVector3(x_,y_,z_);
 
  490             tofit2 = 
new TVector3(x_,y_,z_bis);
 
  495             Double_t zcoord_ = z0 + zslope * scosl_;
 
  496             TVector3 *tofit3 = 
new TVector3(x_, y_, zcoord_);
 
  498             double distance_1 = 
sqrt((tofit->X() - tofit3->X())*(tofit->X() - tofit3->X())
 
  499                                      + (tofit->Y() - tofit3->Y())*(tofit->Y() - tofit3->Y())
 
  500                                      + (tofit->Z() - tofit3->Z())*(tofit->Z() - tofit3->Z()));
 
  502             double distance_2 = 
sqrt((tofit2->X() - tofit3->X())*(tofit2->X() - tofit3->X())
 
  503                                      + (tofit2->Y() - tofit3->Y())*(tofit2->Y() - tofit3->Y())
 
  504                                      + (tofit2->Z() - tofit3->Z())*(tofit2->Z() - tofit3->Z()));
 
  506             if(distance_1 < distance_2) helixhit->SetPosition(*tofit);
 
  507             else helixhit->SetPosition(*tofit2);
 
  519         hxs->Fill(iPoint->GetX() - helixhit->GetX());
 
  520         hys->Fill(iPoint->GetY() - helixhit->GetY());
 
  521         hzs->Fill(iPoint->GetZ() - helixhit->GetZ());
 
  522         hzresvsslope->Fill(zslope, (iPoint->GetZ() - helixhit->GetZ()));
 
  530         TObjArray *volumeArray = 
gGeoManager->GetListOfVolumes();   
 
  532         for(
int i = 0; 
i < volumeArray->GetEntriesFast() ; 
i++)
 
  534             tubename = volumeArray->At(
i)->GetName();
 
  535             if(tubename.Contains(
"stt") && tubename.Contains(
"gas")) 
 
  537                 gastube = (TGeoVolume*) volumeArray->At(
i);
 
  541         TGeoTube *geotube = (TGeoTube*) gastube->GetShape();
 
  542         Double_t tuberadius = geotube->GetRmax();
 
  543         Double_t distance = 2 * 
sqrt(tuberadius * tuberadius - radius * radius); 
 
  545         distance = distance / coslam;    
 
  548         if (distance != 0)  dedx = currenthit->
GetDepCharge()/(1000000 * distance);  
 
  558       cout << 
"-I- PndSttHelixHitProducer: " << j << 
" track " << hitcounter << 
" SttHits, " 
  559            << hotcounter << 
" HelixHits created." << endl;
 
  560       cout << 
"----------------------------------------" << endl;
 
  568   TFile* 
file = FairRootManager::Instance()->GetOutFile();
 
  570   file->mkdir(
"PndSttHelixHit");
 
  571   file->cd(
"PndSttHelixHit");
 
friend F32vec4 cos(const F32vec4 &a)
friend F32vec4 sqrt(const F32vec4 &a)
Int_t GetTrackCandIndex()
static T Sqrt(const T &x)
friend F32vec4 sin(const F32vec4 &a)
PndTrackCandHit GetSortedHit(UInt_t i)
TClonesArray * fTrackArray
void SetPersistency(Bool_t val=kTRUE)
TClonesArray * fTubeArray
virtual void Exec(Option_t *opt)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
TGeoManager * gGeoManager
~PndSttHelixHitProducer()
void AddHelixHit(Int_t size, Int_t index, Int_t helixhitindex)
TClonesArray * fHelixHitArray
virtual InitStatus Init()
Double_t GetIsochrone() const 
PndGeoSttPar * fSttParameters
TClonesArray * FillTubeArray()
Double_t GetIsochroneError() const 
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 fabs(const F32vec4 &a)
Double_t GetDepCharge() const 
Double_t CalculateScosl(Double_t x, Double_t y)
void SetdEdx(Double_t dedx)
TVector3 GetWireDirection()
TClonesArray * fPointArray
TClonesArray * fTrackCandArray