CbmSttHelixTrackFitter.cxx 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601
  1. //
  2. #include <string>
  3. #include <sstream>
  4. #include "CbmSttHelixTrackFitter.h"
  5. #include "CbmSttTrackMatch.h"
  6. #include "FairRootManager.h"
  7. #include "FairTask.h"
  8. #include "TArc.h"
  9. #include "TH2.h"
  10. #include "TClonesArray.h"
  11. // #include "TH3.h"
  12. // #include "TLine.h"
  13. #include "TMatrixD.h" // stt1
  14. #include "TMarker.h"
  15. #include "TLine.h"
  16. #include "TPolyLine.h"
  17. #include "TMinuit.h"
  18. //#include "CbmSttGeomPoint.h"
  19. #include <iostream>
  20. #include "TMath.h"
  21. using std::cout;
  22. using std::cerr;
  23. using std::endl;
  24. // #define rootoutput kFALSE
  25. TH2F *h3;
  26. TCanvas *eventCanvas3;
  27. TArrayD marray(100);
  28. CbmSttHelixTrackFitter::CbmSttHelixTrackFitter()
  29. {
  30. fEventCounter = 0;
  31. // fHotArray = new TClonesArray("CbmSttHOT");
  32. }
  33. CbmSttHelixTrackFitter::CbmSttHelixTrackFitter(Int_t verbose)
  34. {
  35. fVerbose = verbose;
  36. if (verbose < 3)
  37. rootoutput = kFALSE;
  38. else
  39. rootoutput = kTRUE;
  40. fEventCounter = 0;
  41. // fHotArray = new TClonesArray("CbmSttHOT");
  42. }
  43. CbmSttHelixTrackFitter::~CbmSttHelixTrackFitter()
  44. {
  45. // if (fHotArray)
  46. // {
  47. // fHotArray->Delete();
  48. // delete fHotArray;
  49. // }
  50. }
  51. void CbmSttHelixTrackFitter::Init()
  52. {
  53. fEventCounter = 0;
  54. // Get and check FairRootManager
  55. FairRootManager
  56. *ioman = FairRootManager::Instance();
  57. if (! ioman)
  58. {
  59. cout << "-E- CbmSttHelixTrackFitter::Init: "
  60. << "RootManager not instantised!" << endl;
  61. // return kFATAL;
  62. }
  63. // Get hit Array
  64. fHitArray = (TClonesArray*) ioman->GetObject("STTHit");
  65. if (!fHitArray)
  66. {
  67. cout << "-W- CbmSttHelixTrackFitter::Init: No Hit array!"
  68. << endl;
  69. }
  70. // Get point Array
  71. fPointArray = (TClonesArray*) ioman->GetObject("STTPoint");
  72. if ( ! fPointArray)
  73. {
  74. cout << "-W- CbmSttHelixTrackFitter::Init: No Point array!"
  75. << endl;
  76. }
  77. // // Create fHotArray
  78. // fHotArray = new TClonesArray("CbmSttHOT",1000);
  79. if(rootoutput) {
  80. h1 = new TH2F("h1","event display - transverse plane",100,-50,50,100,-50,50);
  81. h2 = new TH2F("h2","z fit",100,-5,20,100,-50,50);
  82. h3 = new TH2F("h3","conformal plane",100,-1.5, 1.5, 100, -1.5, 1.5);
  83. eventCanvas = new TCanvas("eventcanvas", "eventcanvas", 600, 600);
  84. eventCanvas2 = new TCanvas("eventcanvas2", "eventcanvas2", 650, 0 ,600, 600);
  85. eventCanvas3 = new TCanvas("eventcanvas3", "eventcanvas3", 650, 0 ,600, 600);
  86. }
  87. }
  88. Int_t CbmSttHelixTrackFitter::DoFit(CbmSttTrack* pTrack, Int_t pidHypo)
  89. {
  90. fEventCounter++;
  91. if(!pTrack) return 0;
  92. fTrack = pTrack;
  93. // fHotArray->Clear();
  94. if(rootoutput) {
  95. char goOnChar;
  96. cout << "press any key to continue: " << endl;
  97. cin >> goOnChar;
  98. eventCanvas->cd();
  99. h1->Draw();
  100. eventCanvas2->cd();
  101. h2->Draw();
  102. cout << "EVENT: " << fEventCounter << endl;
  103. eventCanvas3->cd();
  104. h3->Draw();
  105. }
  106. Int_t fit = 0;
  107. fit = Fit4b(pTrack, 1);
  108. if(fit == 0 || pTrack->GetParamLast()->GetTx() == 0 || !(pTrack->GetParamLast()->GetTx()) || pTrack->GetParamLast()->GetTx() > 3000) {
  109. cout << "PREPREFIT FAILED " << fit << " " << pTrack->GetParamLast()->GetTx() << endl;
  110. pTrack->GetParamLast()->SetTx(-999);
  111. return 0;
  112. }
  113. cout << "prefit-------------------------------" << endl;
  114. fit = 0;
  115. fit = MinuitFit(pTrack, 1);
  116. // if the fit fails
  117. if(fit == 0 || pTrack->GetParamLast()->GetTx() == 0 || !(pTrack->GetParamLast()->GetTx()) || pTrack->GetParamLast()->GetTx() > 3000) {
  118. pTrack->GetParamLast()->SetTx(-999);
  119. cout << "PREFIT FAILED" << endl;
  120. return 0;
  121. }
  122. else {
  123. pTrack->SetFlag(1); // prefit done
  124. Bool_t Rint = IntersectionFinder(pTrack, pTrack->GetParamLast());
  125. cout << "refit" << endl;
  126. // se il refit e' andato bene
  127. if(Rint == kTRUE) fit = Fit4b(pTrack, 2);
  128. if(fit == 1 && pTrack->GetParamLast()->GetTx() != 0 && (pTrack->GetParamLast()->GetTx()) != 0 && pTrack->GetParamLast()->GetTx() < 3000) {
  129. pTrack->SetFlag(2); // refit done
  130. Bool_t zint = ZFinder(pTrack, 1);
  131. if(zint == kTRUE) {
  132. Int_t zfit = Zfit(pTrack, 1);
  133. if(zfit == 1) {
  134. pTrack->SetFlag(3); // z fit done
  135. }
  136. }
  137. }
  138. }
  139. cout << "param last x: " << pTrack->GetParamLast()->GetX() << endl;
  140. cout << "param last y: " << pTrack->GetParamLast()->GetY() << endl;
  141. cout << "param last tx: " << pTrack->GetParamLast()->GetTx() << endl;
  142. cout << "param last ty: " << pTrack->GetParamLast()->GetTy() << endl;
  143. cout << "param last qp: " << pTrack->GetParamLast()->GetQp() << endl;
  144. if(rootoutput) {
  145. eventCanvas->Update();
  146. eventCanvas->Modified();
  147. eventCanvas2->Update();
  148. eventCanvas2->Modified();
  149. }
  150. return 0;
  151. }
  152. // Int_t CbmSttHelixTrackFitter::AddHitOnTrack(CbmSttTrack *pTrack) {
  153. // if(!pTrack) return 0;
  154. // Int_t hitcounter = pTrack->GetNofHits();
  155. // for (Int_t k = 0; k < hitcounter; k++) {
  156. // Int_t iHit = pTrack->GetHitIndex(k);
  157. // CbmSttHit *currenthit = (CbmSttHit*) fHitArray->At(iHit);
  158. // if(currenthit->GetXint() == -999 || currenthit->GetXint() == -999) continue;
  159. // Int_t refindex = currenthit->GetRefIndex();
  160. // // get point
  161. // CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  162. // TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  163. // // cout << "x: " << currenthit->GetXint() << endl;
  164. // // cout << "y: " << currenthit->GetYint() << endl;
  165. // // cout << "z: " << currenthit->GetZint() << endl;
  166. // // axial tubes
  167. // if(wiredirection != TVector3(0.,0.,1.)) {
  168. // AddHOT(currenthit->GetXint(), currenthit->GetYint(), -999, iHit, refindex, 0);
  169. // }
  170. // // skewd tubes
  171. // else {
  172. // AddHOT(currenthit->GetXint(), currenthit->GetYint(), currenthit->GetZint(), iHit, refindex, 0);
  173. // }
  174. // }
  175. // // pTrack->SetHOT(fHotArray);
  176. // // fHotArray->Clear();
  177. // return 0;
  178. // }
  179. Int_t CbmSttHelixTrackFitter::Fit4(CbmSttTrack* pTrack, Int_t pidHypo) {
  180. if(!pTrack) return 0;
  181. Int_t hitcounter = pTrack->GetNofHits();
  182. Bool_t first = kFALSE;
  183. if(hitcounter == 0) return 0;
  184. if(hitcounter > 50 || hitcounter < 5) {
  185. cout << "Bad No of hits in STT " << hitcounter << endl;
  186. return 0;
  187. }
  188. cout << "FIT 4 ********************" << endl;
  189. // traslation and rotation -----------
  190. // traslation near the first point
  191. Double_t s = 0.001;
  192. Double_t trasl[2];
  193. // rotation
  194. Double_t alpha;
  195. cout << "hitcounter: " << hitcounter << endl;
  196. for(Int_t k = 0; k <hitcounter; k++) {
  197. Int_t iHit = pTrack->GetHitIndex(k);
  198. CbmSttHit *currenthit = (CbmSttHit*) fHitArray->At(iHit);
  199. if(!currenthit) continue;
  200. if(currenthit->GetXint() == -999 || currenthit->GetYint() == -999) continue;
  201. Int_t refindex = currenthit->GetRefIndex();
  202. // get point
  203. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  204. CbmSttHit *hitfirst, *hitlast;
  205. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  206. if(wiredirection != TVector3(0.,0.,1.)) continue;
  207. else if(first == kFALSE){
  208. hitfirst = (CbmSttHit*) fHitArray->At(iHit);
  209. first = kTRUE;
  210. trasl[0] = hitfirst->GetXint();
  211. trasl[1] = hitfirst->GetYint();
  212. }
  213. else{
  214. hitlast = (CbmSttHit*) fHitArray->At(iHit);
  215. alpha = TMath::ATan2(hitlast->GetYint() - hitfirst->GetYint(), hitlast->GetXint() - hitfirst->GetXint());
  216. }
  217. }
  218. // error <--> resolution
  219. Double_t sigr, sigxy, sigx, sigy; // = 0.14;
  220. // FITTING IN X-Y PLANE:
  221. // v = a + bu + cu^2
  222. Double_t Suu, Su, Sv, Suv, S1, Suuu, Suuv, Suuuu;
  223. Su = 0.;
  224. Sv = 0.;
  225. Suu = 0.;
  226. Suv = 0.;
  227. Suuu = 0.;
  228. S1 = 0.;
  229. Suuv = 0.;
  230. Suuuu = 0.;
  231. Int_t digicounter = 0;
  232. TArrayD uarray(hitcounter);
  233. TArrayD varray(hitcounter);
  234. TArrayD sigv2array(hitcounter);
  235. TArrayD sigu2array(hitcounter);
  236. for(Int_t i=0; i < hitcounter; i++){
  237. uarray.AddAt(-999, i);
  238. varray.AddAt(-999, i);
  239. sigv2array.AddAt(-999, i);
  240. sigu2array.AddAt(-999, i);
  241. }
  242. for(Int_t i=0; i < hitcounter; i++){
  243. Int_t iHit = pTrack->GetHitIndex(i);
  244. CbmSttHit *currenthit = (CbmSttHit*) fHitArray->At(iHit);
  245. if(!currenthit) continue;
  246. if(currenthit->GetXint() == -999 || currenthit->GetYint() == -999) continue;
  247. Int_t refindex = currenthit->GetRefIndex();
  248. // get point
  249. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  250. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  251. if(wiredirection != TVector3(0.,0.,1.)) continue;
  252. if(pidHypo == 2) {
  253. Double_t resx = iPoint->GetXtot() - currenthit->GetXint();
  254. Double_t resy = iPoint->GetYtot() - currenthit->GetYint();
  255. Double_t resdist = TMath::Sqrt((iPoint->GetYtot() - currenthit->GetYint())*(iPoint->GetYtot() - currenthit->GetYint()) + (iPoint->GetXtot() - currenthit->GetXint())*(iPoint->GetXtot() - currenthit->GetXint()));
  256. }
  257. if(rootoutput) {
  258. // if(pidHypo == 2) {
  259. eventCanvas->cd();
  260. TMarker *cir1 = new TMarker(currenthit->GetXint(), currenthit->GetYint(), 6);
  261. cir1->SetMarkerColor(2);
  262. if(pidHypo == 2) cir1->Draw("SAME");
  263. TMarker *cir2 = new TMarker(currenthit->GetX(), currenthit->GetY(), 6);
  264. if(pidHypo == 1) cir2->Draw("SAME");
  265. // }
  266. }
  267. Double_t xtrasl, ytrasl;
  268. // traslation
  269. xtrasl = currenthit->GetXint() - trasl[0];
  270. ytrasl = currenthit->GetYint() - trasl[1];
  271. Double_t xrot, yrot;
  272. // rotation
  273. xrot = TMath::Cos(alpha)*xtrasl + TMath::Sin(alpha)*ytrasl;
  274. yrot = -TMath::Sin(alpha)*xtrasl + TMath::Cos(alpha)*ytrasl;
  275. // re-traslation
  276. xtrasl = xrot + s;
  277. ytrasl = yrot;
  278. if(rootoutput) {
  279. eventCanvas->cd();
  280. TMarker *pt = new TMarker(xrot, yrot, 6);
  281. pt->SetMarkerColor(3);
  282. // if(pidHypo == 2)
  283. // pt->Draw("SAME");
  284. }
  285. // change coordinate
  286. Double_t u, v, sigv2, sigu2;
  287. u = xtrasl / (xtrasl*xtrasl + ytrasl*ytrasl);
  288. v = ytrasl / (xtrasl*xtrasl + ytrasl*ytrasl);
  289. if(rootoutput){// && pidHypo == 2) {
  290. eventCanvas3->cd();
  291. TMarker *uv = new TMarker(u, v, 6);
  292. uv->SetMarkerColor(3);
  293. if(pidHypo == 2) uv->Draw("SAME");
  294. eventCanvas3->Update();
  295. eventCanvas3->Modified();
  296. }
  297. if(pidHypo == 1) {
  298. sigr = sqrt(2.) * currenthit->GetIsochrone()/sqrt(12.);
  299. sigx = sigr;
  300. sigy = sigr;
  301. }
  302. else {
  303. sigr = 0.0150;
  304. sigx = fabs(sigr * TMath::Cos(TMath::ATan(marray.At(i))));
  305. sigy = fabs(sigr * TMath::Sin(TMath::ATan(marray.At(i))));
  306. sigxy = sigr * TMath::Sqrt(fabs(TMath::Cos(TMath::ATan(marray.At(i))) * TMath::Sin(TMath::ATan(marray.At(i)))));;
  307. }
  308. Double_t dvdx = (-2 * xtrasl * ytrasl)/pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  309. Double_t dvdy = (xtrasl*xtrasl - ytrasl*ytrasl) / pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  310. Double_t dudx = (ytrasl*ytrasl - xtrasl*xtrasl) / pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  311. Double_t dudy = (-2 * xtrasl * ytrasl)/pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  312. sigu2 = dudx * dudx * sigx * sigx + dudy * dudy * sigy * sigy + 2 * dudx * dudy * sigx * sigy;
  313. sigv2 = dvdx * dvdx * sigx * sigx + dvdy * dvdy * sigy * sigy + 2 * dvdx * dvdy * sigx * sigy;
  314. uarray.AddAt(u, digicounter);
  315. varray.AddAt(v, digicounter);
  316. sigu2array.AddAt(sigu2, digicounter);
  317. sigv2array.AddAt(sigv2, digicounter);
  318. Su = Su + (u/sigv2);
  319. Sv = Sv + (v/sigv2);
  320. Suv = Suv + ((u*v)/sigv2);
  321. Suu = Suu + ((u*u)/sigv2);
  322. Suuu = Suuu + ((u*u*u)/sigv2);
  323. Suuv = Suuv + ((u*u*v)/sigv2);
  324. Suuuu = Suuuu + ((u*u*u*u)/sigv2);
  325. S1 = S1 + 1/sigv2;
  326. digicounter++;
  327. }
  328. TMatrixD matrix(3,3);
  329. matrix[0][0] = S1;
  330. matrix[0][1] = Su;
  331. matrix[0][2] = Suu;
  332. matrix[1][0] = Su;
  333. matrix[1][1] = Suu;
  334. matrix[1][2] = Suuu;
  335. matrix[2][0] = Suu;
  336. matrix[2][1] = Suuu;
  337. matrix[2][2] = Suuuu;
  338. Double_t determ;
  339. determ = matrix.Determinant();
  340. if (determ != 0) {
  341. matrix.Invert();
  342. }
  343. else {
  344. return 0;
  345. cout << "DET 0" << endl;
  346. }
  347. TMatrixD column(3,1);
  348. column[0][0] = Sv;
  349. column[1][0] = Suv;
  350. column[2][0] = Suuv;
  351. TMatrixD column2(3,1);
  352. column2.Mult(matrix, column);
  353. Double_t a, b, c;
  354. a = column2[0][0];
  355. b = column2[1][0];
  356. c = column2[2][0];
  357. // std::cout << "1) parabolic parameters:\n";
  358. // std::cout << "a = " << column2[0][0] << "\n";
  359. // std::cout << "b = " << column2[1][0] << "\n";
  360. // std::cout << "c = " << column2[2][0] << "\n";
  361. Double_t chi2;
  362. chi2 = 0.;
  363. for(Int_t i=0; i < digicounter; i++){
  364. if(uarray.At(i) == -999 || varray.At(i) == -999 || sigv2array.At(i) == -999) continue;
  365. chi2 = chi2 + pow(((varray.At(i) - (a + b*uarray.At(i) + c*uarray.At(i)*uarray.At(i))) /sqrt(sigv2array.At(i))),2) ;
  366. }
  367. //------------------ with right errors
  368. Su = 0.;
  369. Sv = 0.;
  370. Suu = 0.;
  371. Suv = 0.;
  372. Suuu = 0.;
  373. S1 = 0.;
  374. Suuv = 0.;
  375. Suuuu = 0.;
  376. TArrayD sigE2array(digicounter);
  377. Double_t sigE2;
  378. for(Int_t i=0; i< digicounter; i++){
  379. if(uarray.At(i) == -999 || varray.At(i) == -999 || sigv2array.At(i) == -999) continue;
  380. sigE2 = sigv2array.At(i) + sigu2array.At(i) * pow((b + 2*c*uarray.At(i)),2);
  381. sigE2array.AddAt(sigE2, i);
  382. Su = Su + (uarray.At(i)/sigE2);
  383. Sv = Sv + (varray.At(i)/sigE2);
  384. Suv = Suv + ((uarray.At(i)*varray.At(i))/sigE2);
  385. Suu = Suu + ((uarray.At(i)*uarray.At(i))/sigE2);
  386. Suuu = Suuu + ((uarray.At(i)*uarray.At(i)*uarray.At(i))/sigE2);
  387. Suuv = Suuv + ((uarray.At(i)*uarray.At(i)*varray.At(i))/sigE2);
  388. Suuuu = Suuuu + ((uarray.At(i)*uarray.At(i)*uarray.At(i)*uarray.At(i))/sigE2);
  389. S1 = S1 + 1/sigE2;
  390. }
  391. TMatrixD matrixb(3,3);
  392. matrixb[0][0] = S1;
  393. matrixb[0][1] = Su;
  394. matrixb[0][2] = Suu;
  395. matrixb[1][0] = Su;
  396. matrixb[1][1] = Suu;
  397. matrixb[1][2] = Suuu;
  398. matrixb[2][0] = Suu;
  399. matrixb[2][1] = Suuu;
  400. matrixb[2][2] = Suuuu;
  401. determ = matrixb.Determinant();
  402. if (determ != 0) {
  403. matrixb.Invert();
  404. }
  405. else {
  406. return 0;
  407. cout << "DET 0" << endl;
  408. }
  409. TMatrixD columnb(3,1);
  410. columnb[0][0] = Sv;
  411. columnb[1][0] = Suv;
  412. columnb[2][0] = Suuv;
  413. TMatrixD column2b(3,1);
  414. column2b.Mult(matrixb, columnb);
  415. a = column2b[0][0];
  416. b = column2b[1][0];
  417. c = column2b[2][0];
  418. // std::cout << "*************\n";
  419. // std::cout << "2) parabolic parameters:\n";
  420. // std::cout << "a = " << column2b[0][0] << "\n";
  421. // std::cout << "b = " << column2b[1][0] << "\n";
  422. // std::cout << "c = " << column2b[2][0] << "\n";
  423. //v = a + bu + cu^2
  424. chi2 = 0.;
  425. for(Int_t i=0; i<digicounter; i++){
  426. if(uarray.At(i) == -999 || varray.At(i) == -999 || sigv2array.At(i) == -999) continue;
  427. chi2 = chi2 + pow(((varray.At(i) - (a + b*uarray.At(i) + c*uarray.At(i)*uarray.At(i)))/sqrt(sigE2array.At(i))), 2);
  428. }
  429. if(rootoutput){// && pidHypo == 2) {
  430. eventCanvas3->cd();
  431. Double_t uu[100];
  432. Double_t vv[100];
  433. for(Int_t p = 0; p<100; p++){
  434. uu[p] = -1.5 + p*3*0.01;
  435. vv[p] = a + b*uu[p] + c*uu[p]*uu[p];
  436. }
  437. TPolyLine *uvline = new TPolyLine(100, uu, vv);
  438. if(pidHypo == 2) uvline->Draw("SAME");
  439. eventCanvas3->Update();
  440. eventCanvas3->Modified();
  441. }
  442. // center and radius
  443. Double_t xcrot, ycrot, xc, yc, epsilon, R;
  444. ycrot = 1/(2*a);
  445. xcrot = -b/(2*a);
  446. epsilon = -c*pow((1+(b*b)), -3/2);
  447. R = epsilon + sqrt((xcrot*xcrot)+(ycrot*ycrot));
  448. // // errors on parameters -------------------
  449. // // a, b, c
  450. // Double_t Da[MAXNUMSTTHITS], Db[MAXNUMSTTHITS], Dc[MAXNUMSTTHITS];
  451. // Double_t p1[MAXNUMSTTHITS], pu[MAXNUMSTTHITS], puu[MAXNUMSTTHITS];
  452. // Double_t erra2, errb2, errc2;
  453. // erra2 = 0.;
  454. // errb2 = 0.;
  455. // errc2 = 0.;
  456. // for(Int_t i=0; i<fTrackNumSttHits[fitTrack]; i++){
  457. // p1[i] = 1/sigE2[i];
  458. // pu[i] = u[i]*p1[i];
  459. // puu[i] = u[i]*pu[i];
  460. // Da[i] = matrixb[0][0] * p1[i] + matrixb[0][1] * pu[i] + matrixb[0][2] * puu[i];
  461. // Db[i] = matrixb[1][0] * p1[i] + matrixb[1][1] * pu[i] + matrixb[1][2] * puu[i];
  462. // Dc[i] = matrixb[2][0] * p1[i] + matrixb[2][1] * pu[i] + matrixb[2][2] * puu[i];
  463. // erra2 = erra2 + (Da[i]*Da[i]*sigE2[i]);
  464. // errb2 = errb2 + (Db[i]*Db[i]*sigE2[i]);
  465. // errc2 = errc2 + (Dc[i]*Dc[i]*sigE2[i]);
  466. // }
  467. // // std::cout << "**************\n";
  468. // // std::cout << "erra = " << sqrt(erra2) << "\n";
  469. // // std::cout << "errb = " << sqrt(errb2)<< "\n";
  470. // // std::cout << "errc = " << sqrt(errc2)<< "\n";
  471. // // errors on xc, yc, R
  472. // Double_t errxcrot2, errycrot2, errR2;
  473. // errxcrot2 = (1./(4*pow(a,4))) * (b*b*erra2 + a*a*errb2 - 2*a*b*sqrt(erra2*errb2)) ;
  474. // errycrot2 = (1./4)*(erra2/pow(a,4)) ;
  475. // errR2 = (1./(R*R)) * (ycrot*ycrot*errxcrot2 + xcrot*xcrot*errycrot2 + 2*xcrot*ycrot*sqrt(errxcrot2*errycrot2)) ;
  476. // re-rotation and re-traslation of xc and yc
  477. // translation
  478. xc = xc - s;
  479. // rotation
  480. xc = TMath::Cos(alpha)*xcrot - TMath::Sin(alpha)*ycrot;
  481. yc = TMath::Sin(alpha)*xcrot + TMath::Cos(alpha)*ycrot;
  482. // traslation
  483. xc = xc + trasl[0];
  484. yc = yc + trasl[1];
  485. // cout << "FIT2: " << xc << " " << yc << endl;
  486. Double_t phi = TMath::ATan2(yc, xc); // CHECK
  487. Double_t d;
  488. d = ((xc + yc) - R*(TMath::Cos(phi) + TMath::Sin(phi)))/(TMath::Cos(phi) + TMath::Sin(phi)); // CHECK
  489. pTrack->GetParamLast()->SetX(d);
  490. pTrack->GetParamLast()->SetY(phi);
  491. // Double_t newZ = -999.; // CHECK da cambiare
  492. // pTrack->GetParamLast()->SetZ(newZ);
  493. pTrack->GetParamLast()->SetTx(R);
  494. // Double_t newTheta = -999.; // CHECK da cambiare
  495. // pTrack->GetParamLast()->SetTy(newTheta);
  496. pTrack->GetParamLast()->SetQp(0.);
  497. // cout << "FIT: " << xc << " " << yc << endl;
  498. // cout << "RAGGIO: " << R << endl;
  499. if(rootoutput) {
  500. eventCanvas->cd();
  501. TArc *fitarc = new TArc(((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY())), ((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY())), pTrack->GetParamLast()->GetTx());
  502. if(pidHypo == 2) fitarc->SetLineColor(2);
  503. fitarc->Draw("SAME");
  504. eventCanvas->Update();
  505. eventCanvas->Modified();
  506. }
  507. return 1;
  508. }
  509. Int_t CbmSttHelixTrackFitter::Fit4b(CbmSttTrack* pTrack, Int_t pidHypo) {
  510. if(!pTrack) return 0;
  511. Int_t hitcounter = pTrack->GetNofHits();
  512. Bool_t first = kFALSE;
  513. if(hitcounter == 0) return 0;
  514. if(hitcounter > 50 || hitcounter < 5) {
  515. cout << "Bad No of hits in STT " << hitcounter << endl;
  516. return 0;
  517. }
  518. cout << "FIT 4b ********************" << endl;
  519. // traslation and rotation -----------
  520. // traslation near the first point
  521. Double_t s = 0.001;
  522. Double_t trasl[2];
  523. // rotation
  524. Double_t alpha;
  525. cout << "hitcounter: " << hitcounter << endl;
  526. for(Int_t k = 0; k <hitcounter; k++) {
  527. Int_t iHit = pTrack->GetHitIndex(k);
  528. CbmSttHit *currenthit = (CbmSttHit*) fHitArray->At(iHit);
  529. if(!currenthit) continue;
  530. if(currenthit->GetXint() == -999 || currenthit->GetYint() == -999) continue;
  531. Int_t refindex = currenthit->GetRefIndex();
  532. // get point
  533. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  534. CbmSttHit *hitfirst, *hitlast;
  535. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  536. if(wiredirection != TVector3(0.,0.,1.)) continue;
  537. else if(first == kFALSE)
  538. {
  539. hitfirst = (CbmSttHit*) fHitArray->At(iHit);
  540. first = kTRUE;
  541. trasl[0] = hitfirst->GetXint();
  542. trasl[1] = hitfirst->GetYint();
  543. }
  544. else{
  545. hitlast = (CbmSttHit*) fHitArray->At(iHit);
  546. alpha = TMath::ATan2(hitlast->GetYint() - hitfirst->GetYint(), hitlast->GetXint() - hitfirst->GetXint());
  547. }
  548. }
  549. // error <--> resolution
  550. Double_t sigr, sigxy, sigx, sigy; // = 0.14;
  551. // FITTING IN X-Y PLANE:
  552. // v = a + bu + cu^2
  553. Double_t Suu, Su, Sv, Suv, S1, Suuu, Suuv, Suuuu;
  554. Su = 0.;
  555. Sv = 0.;
  556. Suu = 0.;
  557. Suv = 0.;
  558. Suuu = 0.;
  559. S1 = 0.;
  560. Suuv = 0.;
  561. Suuuu = 0.;
  562. Int_t digicounter = 0;
  563. TArrayD uarray(hitcounter);
  564. TArrayD varray(hitcounter);
  565. TArrayD sigv2array(hitcounter);
  566. TArrayD sigu2array(hitcounter);
  567. for(Int_t i=0; i < hitcounter; i++){
  568. uarray.AddAt(-999, i);
  569. varray.AddAt(-999, i);
  570. sigv2array.AddAt(-999, i);
  571. sigu2array.AddAt(-999, i);
  572. }
  573. for(Int_t i=0; i < hitcounter; i++){
  574. Int_t iHit = pTrack->GetHitIndex(i);
  575. CbmSttHit *currenthit = (CbmSttHit*) fHitArray->At(iHit);
  576. if(!currenthit) continue;
  577. if(currenthit->GetXint() == -999 || currenthit->GetYint() == -999) continue;
  578. Int_t refindex = currenthit->GetRefIndex();
  579. // get point
  580. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  581. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  582. if(wiredirection != TVector3(0.,0.,1.)) continue;
  583. if(pidHypo == 2) {
  584. Double_t resx = iPoint->GetXtot() - currenthit->GetXint();
  585. Double_t resy = iPoint->GetYtot() - currenthit->GetYint();
  586. Double_t resdist = TMath::Sqrt((iPoint->GetYtot() - currenthit->GetYint())*(iPoint->GetYtot() - currenthit->GetYint()) + (iPoint->GetXtot() - currenthit->GetXint())*(iPoint->GetXtot() - currenthit->GetXint()));
  587. }
  588. if(rootoutput) {
  589. // if(pidHypo == 2) {
  590. eventCanvas->cd();
  591. if(pidHypo == 1) {
  592. // draw MC hits
  593. TMarker *cir0 = new TMarker(iPoint->GetXtot(), iPoint->GetYtot(), 6);
  594. cir0->SetMarkerStyle(6);
  595. cir0->SetMarkerColor(4);
  596. // cir0->Draw("SAME");
  597. // cout << "MC: " << iPoint->GetXtot() << " " << iPoint->GetYtot() << endl;
  598. }
  599. TMarker *cir1 = new TMarker(currenthit->GetXint(), currenthit->GetYint(), 6);
  600. cir1->SetMarkerColor(2);
  601. if(pidHypo == 2) cir1->Draw("SAME");
  602. TMarker *cir2 = new TMarker(currenthit->GetX(), currenthit->GetY(), 6);
  603. if(pidHypo == 1) cir2->Draw("SAME");
  604. // }
  605. }
  606. Double_t xtrasl, ytrasl;
  607. // traslation
  608. xtrasl = currenthit->GetXint() - trasl[0];
  609. ytrasl = currenthit->GetYint() - trasl[1];
  610. Double_t xrot, yrot;
  611. // rotation
  612. xrot = TMath::Cos(alpha)*xtrasl + TMath::Sin(alpha)*ytrasl;
  613. yrot = -TMath::Sin(alpha)*xtrasl + TMath::Cos(alpha)*ytrasl;
  614. // re-traslation
  615. xtrasl = xrot + s;
  616. ytrasl = yrot;
  617. if(rootoutput) {
  618. eventCanvas->cd();
  619. TMarker *pt = new TMarker(xrot, yrot, 6);
  620. pt->SetMarkerColor(3);
  621. // if(pidHypo == 2)
  622. // pt->Draw("SAME");
  623. }
  624. // change coordinate
  625. Double_t u, v, sigv2, sigu2;
  626. u = xtrasl / (xtrasl*xtrasl + ytrasl*ytrasl);
  627. v = ytrasl / (xtrasl*xtrasl + ytrasl*ytrasl);
  628. if(rootoutput){// && pidHypo == 2) {
  629. eventCanvas3->cd();
  630. TMarker *uv = new TMarker(u, v, 6);
  631. uv->SetMarkerColor(3);
  632. if(pidHypo == 2) uv->Draw("SAME");
  633. eventCanvas3->Update();
  634. eventCanvas3->Modified();
  635. }
  636. if(pidHypo == 1) {
  637. if(currenthit->GetIsochrone() == 0) sigr = sqrt(2.)/sqrt(12.);
  638. else sigr = sqrt(2.) * currenthit->GetIsochrone()/sqrt(12.);
  639. sigx = sigr;
  640. sigy = sigr;
  641. }
  642. else {
  643. if(currenthit->GetIsochrone() == 0) {
  644. sigr = sqrt(2.)/sqrt(12.);
  645. sigx = sigr;
  646. sigy = sigr;
  647. }
  648. else {
  649. sigr = 0.0150;
  650. sigx = fabs(sigr * TMath::Cos(TMath::ATan(marray.At(i))));
  651. sigy = fabs(sigr * TMath::Sin(TMath::ATan(marray.At(i))));
  652. sigxy = sigr * TMath::Sqrt(fabs(TMath::Cos(TMath::ATan(marray.At(i))) * TMath::Sin(TMath::ATan(marray.At(i)))));;
  653. }
  654. }
  655. Double_t dvdx = (-2 * xtrasl * ytrasl)/pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  656. Double_t dvdy = (xtrasl*xtrasl - ytrasl*ytrasl) / pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  657. Double_t dudx = (ytrasl*ytrasl - xtrasl*xtrasl) / pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  658. Double_t dudy = (-2 * xtrasl * ytrasl)/pow((xtrasl*xtrasl + ytrasl*ytrasl),2);
  659. sigu2 = dudx * dudx * sigx * sigx + dudy * dudy * sigy * sigy + 2 * dudx * dudy * sigx * sigy;
  660. sigv2 = dvdx * dvdx * sigx * sigx + dvdy * dvdy * sigy * sigy + 2 * dvdx * dvdy * sigx * sigy;
  661. uarray.AddAt(u, digicounter);
  662. varray.AddAt(v, digicounter);
  663. sigu2array.AddAt(sigu2, digicounter);
  664. sigv2array.AddAt(sigv2, digicounter);
  665. Su = Su + (u/sigv2);
  666. Sv = Sv + (v/sigv2);
  667. Suv = Suv + ((u*v)/sigv2);
  668. Suu = Suu + ((u*u)/sigv2);
  669. Suuu = Suuu + ((u*u*u)/sigv2);
  670. Suuv = Suuv + ((u*u*v)/sigv2);
  671. Suuuu = Suuuu + ((u*u*u*u)/sigv2);
  672. S1 = S1 + 1/sigv2;
  673. digicounter++;
  674. }
  675. TMatrixD matrix(3,3);
  676. matrix[0][0] = S1;
  677. matrix[0][1] = Su;
  678. matrix[0][2] = Suu;
  679. matrix[1][0] = Su;
  680. matrix[1][1] = Suu;
  681. matrix[1][2] = Suuu;
  682. matrix[2][0] = Suu;
  683. matrix[2][1] = Suuu;
  684. matrix[2][2] = Suuuu;
  685. Double_t determ;
  686. determ = matrix.Determinant();
  687. if (determ != 0) {
  688. matrix.Invert();
  689. }
  690. else {
  691. return 0;
  692. cout << "DET 0" << endl;
  693. }
  694. TMatrixD column(3,1);
  695. column[0][0] = Sv;
  696. column[1][0] = Suv;
  697. column[2][0] = Suuv;
  698. TMatrixD column2(3,1);
  699. column2.Mult(matrix, column);
  700. Double_t a, b, c;
  701. a = column2[0][0];
  702. b = column2[1][0];
  703. c = column2[2][0];
  704. // std::cout << "1) parabolic parameters:\n";
  705. // std::cout << "a = " << column2[0][0] << "\n";
  706. // std::cout << "b = " << column2[1][0] << "\n";
  707. // std::cout << "c = " << column2[2][0] << "\n";
  708. Double_t chi2;
  709. chi2 = 0.;
  710. for(Int_t i=0; i < digicounter; i++){
  711. if(uarray.At(i) == -999 || varray.At(i) == -999 || sigv2array.At(i) == -999) continue;
  712. chi2 = chi2 + pow(((varray.At(i) - (a + b*uarray.At(i) + c*uarray.At(i)*uarray.At(i))) /sqrt(sigv2array.At(i))),2) ;
  713. }
  714. cout << "digicounter: " << digicounter << endl;
  715. //------------------ with right errors
  716. Su = 0.;
  717. Sv = 0.;
  718. Suu = 0.;
  719. Suv = 0.;
  720. Suuu = 0.;
  721. S1 = 0.;
  722. Suuv = 0.;
  723. Suuuu = 0.;
  724. TArrayD sigE2array(digicounter);
  725. Double_t sigE2;
  726. for(Int_t i=0; i< digicounter; i++){
  727. if(uarray.At(i) == -999 || varray.At(i) == -999 || sigv2array.At(i) == -999) continue;
  728. sigE2 = sigv2array.At(i) + sigu2array.At(i) * pow((b + 2*c*uarray.At(i)),2);
  729. sigE2array.AddAt(sigE2, i);
  730. Su = Su + (uarray.At(i)/sigE2);
  731. Sv = Sv + (varray.At(i)/sigE2);
  732. Suv = Suv + ((uarray.At(i)*varray.At(i))/sigE2);
  733. Suu = Suu + ((uarray.At(i)*uarray.At(i))/sigE2);
  734. Suuu = Suuu + ((uarray.At(i)*uarray.At(i)*uarray.At(i))/sigE2);
  735. Suuv = Suuv + ((uarray.At(i)*uarray.At(i)*varray.At(i))/sigE2);
  736. Suuuu = Suuuu + ((uarray.At(i)*uarray.At(i)*uarray.At(i)*uarray.At(i))/sigE2);
  737. S1 = S1 + 1/sigE2;
  738. }
  739. TMatrixD matrixb(3,3);
  740. matrixb[0][0] = S1;
  741. matrixb[0][1] = Su;
  742. matrixb[0][2] = Suu;
  743. matrixb[1][0] = Su;
  744. matrixb[1][1] = Suu;
  745. matrixb[1][2] = Suuu;
  746. matrixb[2][0] = Suu;
  747. matrixb[2][1] = Suuu;
  748. matrixb[2][2] = Suuuu;
  749. determ = matrixb.Determinant();
  750. if (determ != 0) {
  751. matrixb.Invert();
  752. }
  753. else {
  754. return 0;
  755. cout << "DET 0" << endl;
  756. }
  757. TMatrixD columnb(3,1);
  758. columnb[0][0] = Sv;
  759. columnb[1][0] = Suv;
  760. columnb[2][0] = Suuv;
  761. TMatrixD column2b(3,1);
  762. column2b.Mult(matrixb, columnb);
  763. a = column2b[0][0];
  764. b = column2b[1][0];
  765. c = column2b[2][0];
  766. // std::cout << "*************\n";
  767. // std::cout << "2) parabolic parameters:\n";
  768. // std::cout << "a = " << column2b[0][0] << "\n";
  769. // std::cout << "b = " << column2b[1][0] << "\n";
  770. // std::cout << "c = " << column2b[2][0] << "\n";
  771. //v = a + bu + cu^2
  772. chi2 = 0.;
  773. for(Int_t i=0; i<digicounter; i++){
  774. if(uarray.At(i) == -999 || varray.At(i) == -999 || sigv2array.At(i) == -999) continue;
  775. chi2 = chi2 + pow(((varray.At(i) - (a + b*uarray.At(i) + c*uarray.At(i)*uarray.At(i)))/sqrt(sigE2array.At(i))), 2);
  776. }
  777. if(rootoutput){// && pidHypo == 2) {
  778. eventCanvas3->cd();
  779. Double_t uu[100];
  780. Double_t vv[100];
  781. for(Int_t p = 0; p<100; p++){
  782. uu[p] = -1.5 + p*3*0.01;
  783. vv[p] = a + b*uu[p] + c*uu[p]*uu[p];
  784. }
  785. TPolyLine *uvline = new TPolyLine(100, uu, vv);
  786. if(pidHypo == 2) uvline->Draw("SAME");
  787. eventCanvas3->Update();
  788. eventCanvas3->Modified();
  789. }
  790. // center and radius
  791. Double_t xcrot, ycrot, xc, yc, epsilon, R;
  792. ycrot = 1/(2*a);
  793. xcrot = -b/(2*a);
  794. epsilon = -c*pow((1+(b*b)), -3/2);
  795. R = epsilon + sqrt((xcrot*xcrot)+(ycrot*ycrot));
  796. // // errors on parameters -------------------
  797. // // a, b, c
  798. // Double_t Da[MAXNUMSTTHITS], Db[MAXNUMSTTHITS], Dc[MAXNUMSTTHITS];
  799. // Double_t p1[MAXNUMSTTHITS], pu[MAXNUMSTTHITS], puu[MAXNUMSTTHITS];
  800. // Double_t erra2, errb2, errc2;
  801. // erra2 = 0.;
  802. // errb2 = 0.;
  803. // errc2 = 0.;
  804. // for(Int_t i=0; i<fTrackNumSttHits[fitTrack]; i++){
  805. // p1[i] = 1/sigE2[i];
  806. // pu[i] = u[i]*p1[i];
  807. // puu[i] = u[i]*pu[i];
  808. // Da[i] = matrixb[0][0] * p1[i] + matrixb[0][1] * pu[i] + matrixb[0][2] * puu[i];
  809. // Db[i] = matrixb[1][0] * p1[i] + matrixb[1][1] * pu[i] + matrixb[1][2] * puu[i];
  810. // Dc[i] = matrixb[2][0] * p1[i] + matrixb[2][1] * pu[i] + matrixb[2][2] * puu[i];
  811. // erra2 = erra2 + (Da[i]*Da[i]*sigE2[i]);
  812. // errb2 = errb2 + (Db[i]*Db[i]*sigE2[i]);
  813. // errc2 = errc2 + (Dc[i]*Dc[i]*sigE2[i]);
  814. // }
  815. // // std::cout << "**************\n";
  816. // // std::cout << "erra = " << sqrt(erra2) << "\n";
  817. // // std::cout << "errb = " << sqrt(errb2)<< "\n";
  818. // // std::cout << "errc = " << sqrt(errc2)<< "\n";
  819. // // errors on xc, yc, R
  820. // Double_t errxcrot2, errycrot2, errR2;
  821. // errxcrot2 = (1./(4*pow(a,4))) * (b*b*erra2 + a*a*errb2 - 2*a*b*sqrt(erra2*errb2)) ;
  822. // errycrot2 = (1./4)*(erra2/pow(a,4)) ;
  823. // errR2 = (1./(R*R)) * (ycrot*ycrot*errxcrot2 + xcrot*xcrot*errycrot2 + 2*xcrot*ycrot*sqrt(errxcrot2*errycrot2)) ;
  824. // re-rotation and re-traslation of xc and yc
  825. // translation
  826. xc = xc - s;
  827. // rotation
  828. xc = TMath::Cos(alpha)*xcrot - TMath::Sin(alpha)*ycrot;
  829. yc = TMath::Sin(alpha)*xcrot + TMath::Cos(alpha)*ycrot;
  830. // traslation
  831. xc = xc + trasl[0];
  832. yc = yc + trasl[1];
  833. Double_t phi = TMath::ATan2(yc, xc); // CHECK
  834. Double_t d;
  835. d = ((xc + yc) - R*(TMath::Cos(phi) + TMath::Sin(phi)))/(TMath::Cos(phi) + TMath::Sin(phi)); // CHECK
  836. pTrack->GetParamLast()->SetX(d);
  837. pTrack->GetParamLast()->SetY(phi);
  838. // Double_t newZ = -999.; // CHECK da cambiare
  839. // pTrack->GetParamLast()->SetZ(newZ);
  840. pTrack->GetParamLast()->SetTx(R);
  841. // Double_t newTheta = -999.; // CHECK da cambiare
  842. // pTrack->GetParamLast()->SetTy(newTheta);
  843. pTrack->GetParamLast()->SetQp(0.);
  844. // cout << "FIT: " << xc << " " << yc << endl;
  845. // cout << "RAGGIO: " << R << endl;
  846. if(rootoutput) {
  847. eventCanvas->cd();
  848. TArc *fitarc = new TArc(((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY())), ((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY())), pTrack->GetParamLast()->GetTx());
  849. if(pidHypo == 2) fitarc->SetLineColor(2);
  850. fitarc->Draw("SAME");
  851. eventCanvas->Update();
  852. eventCanvas->Modified();
  853. }
  854. return 1;
  855. }
  856. // -------------- IntersectionFinder --------------------------------------
  857. Bool_t CbmSttHelixTrackFitter::IntersectionFinder(CbmSttTrack *pTrack, FairTrackParam *par)
  858. {
  859. ResetMArray();
  860. // calculation of the curvature from the helix prefit
  861. if(pTrack->GetParamLast()->GetTx() == 0) return kFALSE;
  862. TVector2 vec((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY()), (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY()));
  863. //==========
  864. // POINT ----------------------------------------------------
  865. // 1. find the cooordinates of the point fired wire of the track
  866. TVector2 point; // point
  867. Double_t radius;
  868. Int_t counter = 0;
  869. // loop over input points
  870. Int_t hitcounter = pTrack->GetNofHits();
  871. for(Int_t k = 0; k < hitcounter; k++){
  872. // get hit
  873. Int_t iHit = pTrack->GetHitIndex(k);
  874. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  875. if (!pMhit ) continue;
  876. Int_t refindex = pMhit->GetRefIndex();
  877. // get point
  878. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  879. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  880. if(wiredirection != TVector3(0.,0.,1.)) continue;
  881. // [xp, yp] point = coordinates xy of the centre of the firing tube
  882. point.Set(pMhit->GetX(), pMhit->GetY());
  883. radius = pMhit->GetIsochrone();
  884. // the coordinates of the point are taken from the intersection
  885. // between the circumference from the drift time and the R radius of
  886. // curvature. -------------------------------------------------------
  887. // 2. find the intersection between the little circle and the line // R
  888. TVector2 first;
  889. TVector2 second;
  890. // 2.a
  891. // find the line passing throught [xc, yc] (centre of curvature) and [xp, yp] (first wire)
  892. // y = mx + q
  893. Double_t m = (point.Y() - vec.Y())/(point.X() - vec.X());
  894. Double_t q = point.Y() - m*point.X();
  895. if(rootoutput) {
  896. eventCanvas->cd();
  897. TArc *archetto = new TArc(point.X(), point.Y(), radius);
  898. archetto->Draw("SAME");
  899. TLine *line = new TLine(-50, -50*m + q, 50, 50*m + q);
  900. line->SetLineColor(4);
  901. // line->Draw("SAME");
  902. eventCanvas->Update();
  903. eventCanvas->Modified();
  904. }
  905. // cut on radius CHECK
  906. // if the simulated radius is too small, the pMhit
  907. // is not used for the fit
  908. if(radius < 0.1) {
  909. marray.AddAt(-999, k);
  910. pMhit->SetXint(-999);
  911. pMhit->SetYint(-999);
  912. continue; // CHECK cosi' butto l' hit
  913. }
  914. // 2.b
  915. // intersection little circle and line --> [x1, y1]
  916. // + and - refer to the 2 possible intersections
  917. // +
  918. Double_t x1 = (-(m*(q - point.Y()) - point.X()) + sqrt((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);
  919. Double_t y1 = m*x1 + q;
  920. first.Set(x1, y1);
  921. // -
  922. Double_t x2 = (-(m*(q - point.Y()) - point.X()) - sqrt((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);
  923. Double_t y2 = m*x2 + q;
  924. second.Set(x2, y2);
  925. // 2.c intersection between line and circle
  926. // +
  927. Double_t xb1 = (-(m*(q - vec.Y()) - vec.X()) + sqrt((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->GetParamLast()->GetTx()) *(pTrack->GetParamLast()->GetTx()) ))) / (m*m + 1);
  928. Double_t yb1 = m*xb1 + q;
  929. // -
  930. Double_t xb2 = (-(m*(q - vec.Y()) - vec.X()) - sqrt((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->GetParamLast()->GetTx()) *(pTrack->GetParamLast()->GetTx())))) / (m*m + 1);
  931. Double_t yb2 = m*xb2 + q;
  932. // calculation of the distance between [xb, yb] and [xp, yp]
  933. Double_t distb1 = sqrt((yb1 - point.Y())*(yb1 - point.Y()) + (xb1 - point.X())*(xb1 - point.X()));
  934. Double_t distb2 = sqrt((yb2 - point.Y())*(yb2 - point.Y()) + (xb2 - point.X())*(xb2 - point.X()));
  935. // choice of [xb, yb]
  936. TVector2 xyb;
  937. if(distb1 > distb2) xyb.Set(xb2, yb2);
  938. else xyb.Set(xb1, yb1);
  939. // calculation of the distance between [x, y] and [xb. yb]
  940. Double_t dist1 = sqrt((xyb.Y() - y1)*(xyb.Y() - y1) + (xyb.X() - x1)*(xyb.X() - x1));
  941. Double_t dist2 = sqrt((xyb.Y() - y2)*(xyb.Y() - y2) + (xyb.X() - x2)*(xyb.X() - x2));
  942. // choice of [x, y]
  943. TVector2 *xy;
  944. if(dist1 > dist2) xy = new TVector2(x2, y2);
  945. else xy = new TVector2(x1, y1); // <========= THIS IS THE NEW POINT to be used for the fit
  946. // SET AS DEBUG
  947. // if (TMath::Sqrt((xy->X() - point.X())*(xy->X() - point.X()) + (xy->Y() - point.Y())*(xy->Y() - point.Y())) - radius > 0.000001) {
  948. // cout << "ATTENZIONE: " << "differenza = " << TMath::Sqrt((xy->X() - point.X())*(xy->X() - point.X()) + (xy->Y() - point.Y())*(xy->Y() - point.Y())) - radius << endl;
  949. // }
  950. // cout << "x hit prima: " << pMhit->GetX() << " " << pMhit->GetXint() << endl;
  951. // cout << prima: " << pMhit->GetXint() << " " << pMhit->GetYint() << " " << pMhit->GetZint() << endl;
  952. marray.AddAt(m, k);
  953. pMhit->SetXint(xy->X());
  954. pMhit->SetYint(xy->Y());
  955. if(rootoutput) {
  956. eventCanvas->cd();
  957. TMarker *np = new TMarker(pMhit->GetXint(), pMhit->GetYint(), 6);
  958. np->SetMarkerColor(4);
  959. // np->Draw("SAME");
  960. eventCanvas->Update();
  961. eventCanvas->Modified();
  962. }
  963. counter++;
  964. }
  965. if(counter==0) return kFALSE;
  966. else return kTRUE;
  967. }
  968. // -------------- IntersectionFinder --------------------------------------
  969. Bool_t CbmSttHelixTrackFitter::IntersectionFinder4b(CbmSttTrack *pTrack, FairTrackParam *par)
  970. // if the drift radius is too small the center of the tube is used
  971. {
  972. ResetMArray();
  973. // calculation of the curvature from the helix prefit
  974. if(pTrack->GetParamLast()->GetTx() == 0) return kFALSE;
  975. TVector2 vec((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY()), (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY()));
  976. //==========
  977. // POINT ----------------------------------------------------
  978. // 1. find the cooordinates of the point fired wire of the track
  979. TVector2 point; // point
  980. Double_t radius;
  981. Int_t counter = 0;
  982. // loop over input points
  983. Int_t hitcounter = pTrack->GetNofHits();
  984. for(Int_t k = 0; k < hitcounter; k++){
  985. // get hit
  986. Int_t iHit = pTrack->GetHitIndex(k);
  987. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  988. if (!pMhit ) continue;
  989. Int_t refindex = pMhit->GetRefIndex();
  990. // get point
  991. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  992. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  993. if(wiredirection != TVector3(0.,0.,1.)) continue;
  994. // [xp, yp] point = coordinates xy of the centre of the firing tube
  995. point.Set(pMhit->GetX(), pMhit->GetY());
  996. radius = pMhit->GetIsochrone();
  997. // the coordinates of the point are taken from the intersection
  998. // between the circumference from the drift time and the R radius of
  999. // curvature. -------------------------------------------------------
  1000. // 2. find the intersection between the little circle and the line // R
  1001. TVector2 first;
  1002. TVector2 second;
  1003. // 2.a
  1004. // find the line passing throught [xc, yc] (centre of curvature) and [xp, yp] (first wire)
  1005. // y = mx + q
  1006. Double_t m = (point.Y() - vec.Y())/(point.X() - vec.X());
  1007. Double_t q = point.Y() - m*point.X();
  1008. if(rootoutput) {
  1009. eventCanvas->cd();
  1010. TArc *archetto = new TArc(point.X(), point.Y(), radius);
  1011. archetto->Draw("SAME");
  1012. TLine *line = new TLine(-50, -50*m + q, 50, 50*m + q);
  1013. line->SetLineColor(4);
  1014. // line->Draw("SAME");
  1015. eventCanvas->Update();
  1016. eventCanvas->Modified();
  1017. }
  1018. // cut on radius CHECK
  1019. // if the simulated radius is too small, the pMhit
  1020. // is not used for the fit
  1021. if(radius < 0.1) {
  1022. marray.AddAt(-999, k);
  1023. pMhit->SetXint(pMhit->GetX());
  1024. pMhit->SetYint(pMhit->GetY());
  1025. continue; // CHECK cosi' butto l' hit
  1026. }
  1027. // 2.b
  1028. // intersection little circle and line --> [x1, y1]
  1029. // + and - refer to the 2 possible intersections
  1030. // +
  1031. Double_t x1 = (-(m*(q - point.Y()) - point.X()) + sqrt((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);
  1032. Double_t y1 = m*x1 + q;
  1033. first.Set(x1, y1);
  1034. // -
  1035. Double_t x2 = (-(m*(q - point.Y()) - point.X()) - sqrt((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);
  1036. Double_t y2 = m*x2 + q;
  1037. second.Set(x2, y2);
  1038. // 2.c intersection between line and circle
  1039. // +
  1040. Double_t xb1 = (-(m*(q - vec.Y()) - vec.X()) + sqrt((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->GetParamLast()->GetTx()) *(pTrack->GetParamLast()->GetTx()) ))) / (m*m + 1);
  1041. Double_t yb1 = m*xb1 + q;
  1042. // -
  1043. Double_t xb2 = (-(m*(q - vec.Y()) - vec.X()) - sqrt((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->GetParamLast()->GetTx()) *(pTrack->GetParamLast()->GetTx())))) / (m*m + 1);
  1044. Double_t yb2 = m*xb2 + q;
  1045. // calculation of the distance between [xb, yb] and [xp, yp]
  1046. Double_t distb1 = sqrt((yb1 - point.Y())*(yb1 - point.Y()) + (xb1 - point.X())*(xb1 - point.X()));
  1047. Double_t distb2 = sqrt((yb2 - point.Y())*(yb2 - point.Y()) + (xb2 - point.X())*(xb2 - point.X()));
  1048. // choice of [xb, yb]
  1049. TVector2 xyb;
  1050. if(distb1 > distb2) xyb.Set(xb2, yb2);
  1051. else xyb.Set(xb1, yb1);
  1052. // calculation of the distance between [x, y] and [xb. yb]
  1053. Double_t dist1 = sqrt((xyb.Y() - y1)*(xyb.Y() - y1) + (xyb.X() - x1)*(xyb.X() - x1));
  1054. Double_t dist2 = sqrt((xyb.Y() - y2)*(xyb.Y() - y2) + (xyb.X() - x2)*(xyb.X() - x2));
  1055. // choice of [x, y]
  1056. TVector2 *xy;
  1057. if(dist1 > dist2) xy = new TVector2(x2, y2);
  1058. else xy = new TVector2(x1, y1); // <========= THIS IS THE NEW POINT to be used for the fit
  1059. // SET AS DEBUG
  1060. // if (TMath::Sqrt((xy->X() - point.X())*(xy->X() - point.X()) + (xy->Y() - point.Y())*(xy->Y() - point.Y())) - radius > 0.000001) {
  1061. // cout << "ATTENZIONE: " << "differenza = " << TMath::Sqrt((xy->X() - point.X())*(xy->X() - point.X()) + (xy->Y() - point.Y())*(xy->Y() - point.Y())) - radius << endl;
  1062. // }
  1063. // cout << "x hit prima: " << pMhit->GetX() << " " << pMhit->GetXint() << endl;
  1064. // cout << prima: " << pMhit->GetXint() << " " << pMhit->GetYint() << " " << pMhit->GetZint() << endl;
  1065. marray.AddAt(m, k);
  1066. pMhit->SetXint(xy->X());
  1067. pMhit->SetYint(xy->Y());
  1068. if(rootoutput) {
  1069. eventCanvas->cd();
  1070. TMarker *np = new TMarker(pMhit->GetXint(), pMhit->GetYint(), 6);
  1071. np->SetMarkerColor(4);
  1072. // np->Draw("SAME");
  1073. eventCanvas->Update();
  1074. eventCanvas->Modified();
  1075. }
  1076. counter++;
  1077. }
  1078. if(counter==0) return kFALSE;
  1079. else return kTRUE;
  1080. }
  1081. // -------- ZFinder --------------------------------------------
  1082. Bool_t CbmSttHelixTrackFitter::ZFinder(CbmSttTrack* pTrack, Int_t pidHypo) {
  1083. if(!pTrack) return 0;
  1084. Int_t hitcounter = pTrack->GetNofHits();
  1085. // cut on number of hits
  1086. if(hitcounter > 30) {
  1087. // cout << "more than 30 hits" << endl;
  1088. // pTrack->GetParamLast()->SetX(-999);
  1089. // pTrack->GetParamLast()->SetY(-999);
  1090. // // Double_t newZ = -999.; // CHECK da cambiare
  1091. // // pTrack->GetParamLast()->SetZ(newZ);
  1092. // pTrack->GetParamLast()->SetTx(-999);
  1093. // // Double_t newTheta = -999.; // CHECK da cambiare
  1094. // // pTrack->GetParamLast()->SetTy(newTheta);
  1095. // pTrack->GetParamLast()->SetQp(0.);
  1096. return 0;
  1097. }
  1098. if(hitcounter < 5) {
  1099. // cout << "less than 5 hits" << endl;
  1100. // pTrack->GetParamLast()->SetX(-999);
  1101. // pTrack->GetParamLast()->SetY(-999);
  1102. // // Double_t newZ = -999.; // CHECK da cambiare
  1103. // // pTrack->GetParamLast()->SetZ(newZ);
  1104. // pTrack->GetParamLast()->SetTx(-999);
  1105. // // Double_t newTheta = -999.; // CHECK da cambiare
  1106. // // pTrack->GetParamLast()->SetTy(newTheta);
  1107. // pTrack->GetParamLast()->SetQp(0.);
  1108. return 0;
  1109. }
  1110. ZPointsArray = new TObjArray(2*hitcounter);
  1111. // SCOSL ======
  1112. // phi0
  1113. TVector3 *v0;
  1114. Double_t Phi0;
  1115. // ============
  1116. // ZFIT =======
  1117. if(hitcounter == 0) return kFALSE;
  1118. Double_t Sxx, Sx, Sz, Sxz, S1z;
  1119. Double_t Detz = 0.;
  1120. Double_t fitm, fitp;
  1121. Double_t sigz = 1.; // CHECK
  1122. Sx = 0.;
  1123. Sz = 0.;
  1124. Sxx = 0.;
  1125. Sxz = 0.;
  1126. S1z = 0.;
  1127. // ============
  1128. TVector3 *tofit, *tofit2;
  1129. // centre of curvature
  1130. Double_t x_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY());
  1131. Double_t y_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY());
  1132. // radius of curvature
  1133. Double_t R = pTrack->GetParamLast()->GetTx();
  1134. Int_t wireOk = 0;
  1135. for (Int_t i = 0; i < hitcounter; i++) {
  1136. // get index of hit
  1137. Int_t iHit = pTrack->GetHitIndex(i);
  1138. // get hit
  1139. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  1140. if(pMhit == NULL) continue;
  1141. Int_t refindex = pMhit->GetRefIndex();
  1142. // get point
  1143. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  1144. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  1145. TVector3 wiredirection2;
  1146. wiredirection2 = 75. * wiredirection;
  1147. TVector3 cenposition(pMhit->GetX(), pMhit->GetY(), 0.); // CHECK! z = 35!!
  1148. TVector3 min, max;
  1149. min = cenposition - wiredirection2;
  1150. max = cenposition + wiredirection2;
  1151. // first extremity
  1152. Double_t x_1= min.X();
  1153. Double_t y_1= min.Y();
  1154. Double_t z_1= min.Z();
  1155. // second extremity
  1156. Double_t x_2= max.X();
  1157. Double_t y_2= max.Y();
  1158. Double_t z_2= max.Z();
  1159. Double_t rcur = pMhit->GetIsochrone();
  1160. if(wiredirection != TVector3(0.,0.,1.))
  1161. {
  1162. wireOk++;
  1163. Double_t a = -999;
  1164. Double_t b = -999;
  1165. Double_t x1 = -9999.;
  1166. Double_t y1 = -9999.;
  1167. Double_t x2 = -9999.;
  1168. Double_t y2 = -9999.;
  1169. // intersection point between the reconstructed
  1170. // circumference and the line joining the centres
  1171. // of the reconstructed circle and the i_th drift circle
  1172. if(fabs(x_2-x_1)>0.0001) {
  1173. a =(y_2-y_1)/(x_2-x_1);
  1174. b =(y_1-a*x_1);
  1175. Double_t A = a*a+1;
  1176. Double_t B = x_0+a*y_0-a*b;
  1177. Double_t C = x_0*x_0+y_0*y_0+b*b-R*R-2*y_0*b;
  1178. if((B*B-A*C)>0) {
  1179. x1= (B+TMath::Sqrt(B*B-A*C))/A;
  1180. x2= (B-TMath::Sqrt(B*B-A*C))/A;
  1181. y1=a*x1+b;
  1182. y2=a*x2+b;
  1183. }
  1184. }
  1185. else if(fabs(y_2-y_1)>0.0001) {
  1186. Double_t A = 1;
  1187. Double_t B = y_0;
  1188. Double_t C = y_0*y_0 +(x_1-x_0)*(x_1-x_0) -R*R;
  1189. if((B*B-A*C)>0) {
  1190. y1= (B+TMath::Sqrt(B*B-A*C))/A;
  1191. y2= (B-TMath::Sqrt(B*B-A*C))/A;
  1192. x1=x2=x_1;
  1193. }
  1194. }
  1195. //x1 and x2 are the 2 intersection points
  1196. Double_t d1=TMath::Sqrt((x1-cenposition.X())*(x1-cenposition.X())+
  1197. (y1-cenposition.Y())*(y1-cenposition.Y()));
  1198. Double_t d2=TMath::Sqrt((x2-cenposition.X())*(x2-cenposition.X())+
  1199. (y2-cenposition.Y())*(y2-cenposition.Y()));
  1200. Double_t x_ = x1;
  1201. Double_t y_ = y1;
  1202. // the intersection point nearest to the drift circle's centre is taken
  1203. if(d2<d1) {x_=x2;y_=y2;}
  1204. // now we need to find the actual centre of the drift circle,
  1205. // by translating the drift circle until it becomes tangent
  1206. // to the reconstructed circle.
  1207. // Two solutions are possible (left rigth abiguity),
  1208. // they are both kept, only the following zed fit will discard the wrong ones.
  1209. // Using the parametric equation of the 3d-straigth line and taking the
  1210. // x points just obtained, the zed coordinate of the skewed tube centre is calculated.
  1211. //solving the equation to find out the centre of the tangent circle
  1212. Double_t A = a*a+1;
  1213. Double_t B = -(a*b-a*y_-x_);
  1214. Double_t C = x_*x_+ y_*y_+b*b-2*b*y_-rcur*rcur;
  1215. if((B*B-A*C)>0) {
  1216. x1= (B+TMath::Sqrt(B*B-A*C))/A;
  1217. x2= (B-TMath::Sqrt(B*B-A*C))/A;
  1218. y1=a*x1+b;
  1219. y2=a*x2+b;
  1220. }
  1221. d1=TMath::Sqrt((x1-cenposition.X())*(x1-cenposition.X())+(y1-cenposition.Y())*(y1-cenposition.Y()));
  1222. d2=TMath::Sqrt((x2-cenposition.X())*(x2-cenposition.X())+(y2-cenposition.Y())*(y2-cenposition.Y()));
  1223. Double_t xcen0=x1;
  1224. Double_t xcen1=x2;
  1225. Double_t ycen0=y1;
  1226. Double_t ycen1=y2;
  1227. if(d2<d1) { // z2 contains the points nearest (in x-y) to the initial centre of the skewed tube
  1228. xcen0=x2;
  1229. xcen1=x1;
  1230. ycen0=y2;
  1231. ycen1=y1;
  1232. }
  1233. // zed association
  1234. if(fabs(x_2-x_1)<0.001) return kFALSE;
  1235. Double_t t_ =(xcen0-x_1)/(x_2-x_1); // x= a_x*t + x_1 [t=1 x=x_2]
  1236. Double_t z_ =(z_2-z_1)*t_ +z_1; // z= a_z*t + z_1 [t=1 z=z_2]
  1237. Double_t t_bis =(xcen1-x_1)/(x_2-x_1); // from x_'s (the 2 solutions of the 2nd order equation)
  1238. Double_t z_bis =(z_2-z_1)*t_bis +z_1; // and the 2 parametric equations the z coord. are obtained
  1239. tofit = new TVector3(xcen0,ycen0,z_);
  1240. ZPointsArray->Add(tofit);
  1241. tofit2 = new TVector3(xcen1,ycen1,z_bis);
  1242. ZPointsArray->Add(tofit2);
  1243. // FIRST CHOICE
  1244. //====================
  1245. // scosl
  1246. Double_t x0;
  1247. Double_t y0;
  1248. if(wireOk == 1) {
  1249. if(tofit != NULL) {
  1250. // phi0
  1251. v0 = new TVector3(tofit->X(), tofit->Y(), tofit->Z());
  1252. }
  1253. else if(tofit2 != NULL) {
  1254. v0 = new TVector3(tofit2->X(), tofit2->Y(), tofit2->Z());
  1255. }
  1256. Phi0 = TMath::ATan2((v0->Y() - y_0),(v0->X() - x_0));
  1257. // CHECK
  1258. // we are using the first digi for the arc length calculation
  1259. // but this may be wrong
  1260. x0 = v0->X();
  1261. y0 = v0->Y();
  1262. }
  1263. TVector3 vi(tofit->X(), tofit->Y(), tofit->Z());
  1264. Double_t scos = R*TMath::ATan2((vi.Y() - y0)*TMath::Cos(Phi0) - (vi.X() - x0)*TMath::Sin(Phi0) , R + (vi.X() - x0) * TMath::Cos(Phi0) + (vi.Y()-y0) * TMath::Sin(Phi0));
  1265. //====================
  1266. if(rootoutput) {
  1267. eventCanvas2->cd();
  1268. TMarker *mrk = new TMarker(scos, tofit->Z(), 6);
  1269. mrk->Draw("SAME");
  1270. }
  1271. //====================
  1272. // zfit
  1273. //
  1274. Sx = Sx + (scos/(sigz * sigz));
  1275. Sz = Sz + (tofit->Z()/(sigz * sigz));
  1276. Sxz = Sxz + ((scos * tofit->Z())/(sigz * sigz));
  1277. Sxx = Sxx + ((scos * scos)/(sigz * sigz));
  1278. S1z = S1z + 1/(sigz * sigz);
  1279. //====================
  1280. // SECOND CHOICE
  1281. //====================
  1282. // scosl
  1283. vi.SetXYZ(tofit2->X(), tofit2->Y(), tofit2->Z());
  1284. scos = R*TMath::ATan2((vi.Y() - y0)*TMath::Cos(Phi0) - (vi.X() - x0)*TMath::Sin(Phi0) , R + (vi.X() - x0) * TMath::Cos(Phi0) + (vi.Y()-y0) * TMath::Sin(Phi0));
  1285. //====================
  1286. //====================
  1287. // zfit
  1288. //
  1289. Sx = Sx + (scos/(sigz * sigz));
  1290. Sz = Sz + (tofit2->Z()/(sigz * sigz));
  1291. Sxz = Sxz + ((scos * tofit2->Z())/(sigz * sigz));
  1292. Sxx = Sxx + ((scos * scos)/(sigz * sigz));
  1293. S1z = S1z + 1/(sigz * sigz);
  1294. //====================
  1295. if(rootoutput) {
  1296. eventCanvas2->cd();
  1297. TMarker *mrk2 = new TMarker(scos, tofit2->Z(), 6);
  1298. mrk2->Draw("SAME");
  1299. }
  1300. }
  1301. }
  1302. cout << "skewed: " << wireOk << endl;
  1303. if(wireOk < 2) return kFALSE;
  1304. Detz = S1z*Sxx - Sx*Sx;
  1305. if(Detz == 0) {
  1306. return kFALSE;
  1307. }
  1308. fitp = (1/Detz)*(Sxx*Sz - Sx*Sxz);
  1309. fitm = (1/Detz)*(S1z*Sxz - Sx*Sz);
  1310. // fiterrp2 = (1/Detz)*Sxx;
  1311. // fiterrm2 = (1/Detz)*S1z;
  1312. if(rootoutput) {
  1313. eventCanvas2->cd();
  1314. TLine *line = new TLine(-20, -20*fitm + fitp, 20, (20*fitm + fitp));
  1315. line->Draw("SAME");
  1316. }
  1317. // Double_t chi2z;
  1318. // chi2z = 0.;
  1319. // for(Int_t i=0; i < hitcounter; i++) {
  1320. // TVector3 * vi= (TVector3 *) ZArray->At(i);
  1321. // chi2z = chi2z + pow(((vi->Z()-(fitp+fitm*scosl->At(i)))/sigz), 2);
  1322. // // RESIDUALS
  1323. // // if(pow(((vi->Z()-(fitp+fitm*scosl[i]))/sigz), 2)>10) continue;
  1324. // // bestz[ctbest]=vi->Z();
  1325. // // bests[ctbest]=scosl[i];
  1326. // // ctbest++;
  1327. // }
  1328. // y = m*x + p
  1329. TVector2 outz(fitm, fitp);
  1330. Int_t counter = 0;
  1331. if(fitm == 0. && fitp == 0.) return kFALSE;
  1332. if( wireOk < 2) return kFALSE;
  1333. wireOk = 0;
  1334. Int_t okcounter = 0;
  1335. for(Int_t i = 0; i < (2*hitcounter); i+=2) {
  1336. // get index of hit
  1337. // cout << i << " counter: " << counter << endl;
  1338. Int_t iHit = pTrack->GetHitIndex(counter);
  1339. counter++;
  1340. // get hit
  1341. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  1342. Int_t refindex = pMhit->GetRefIndex();
  1343. // get point
  1344. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  1345. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  1346. if(wiredirection == TVector3(0.,0.,1.)) continue;
  1347. wireOk++;
  1348. sigz = 1.; // CHECK
  1349. Double_t x0;
  1350. Double_t y0;
  1351. if(wireOk==1) {
  1352. TVector3 *vi = (TVector3*) ZPointsArray->At(okcounter);
  1353. // phi0
  1354. v0->SetXYZ(vi->X(), vi->Y(), vi->Z());
  1355. Phi0 = TMath::ATan2((v0->Y() - y_0),(v0->X() - x_0));
  1356. // CHECK
  1357. // we are using the first digi for the arc length calculation
  1358. // but this may be wrong
  1359. x0 = v0->X();
  1360. y0 = v0->Y();
  1361. }
  1362. // FIRST CHOICE
  1363. TVector3 *vi = (TVector3*) ZPointsArray->At(okcounter);
  1364. if(vi == NULL) continue;
  1365. Double_t scos = R*TMath::ATan2((vi->Y() - y0)*TMath::Cos(Phi0) - (vi->X() - x0)*TMath::Sin(Phi0) , R + (vi->X() - x0) * TMath::Cos(Phi0) + (vi->Y()-y0) * TMath::Sin(Phi0));
  1366. Bool_t fitdone = kFALSE;
  1367. Double_t distfirst = pow(((vi->Z() - (outz.Y() + outz.X() * scos))/sigz), 2);
  1368. if(distfirst < 10) {
  1369. pMhit->SetXint(vi->X());
  1370. pMhit->SetYint(vi->Y());
  1371. pMhit->SetZint(vi->Z());
  1372. fitdone = kTRUE;
  1373. }
  1374. // SECOND CHOICE
  1375. vi = (TVector3*) ZPointsArray->At(okcounter+1);
  1376. if(vi == NULL) continue;
  1377. scos = R*TMath::ATan2((vi->Y() - y0)*TMath::Cos(Phi0) - (vi->X() - x0)*TMath::Sin(Phi0) , R + (vi->X() - x0) * TMath::Cos(Phi0) + (vi->Y()-y0) * TMath::Sin(Phi0));
  1378. Double_t distsecond = pow(((vi->Z() - (outz.Y() + outz.X() * scos))/sigz), 2);
  1379. if(fitdone == kTRUE){
  1380. if(distsecond < 10 && distsecond < distfirst) {
  1381. pMhit->SetXint(vi->X());
  1382. pMhit->SetYint(vi->Y());
  1383. pMhit->SetZint(vi->Z());
  1384. }
  1385. }
  1386. else {
  1387. if (distsecond < 10) {
  1388. pMhit->SetXint(vi->X());
  1389. pMhit->SetYint(vi->Y());
  1390. pMhit->SetZint(vi->Z());
  1391. fitdone = kTRUE;
  1392. }
  1393. else {
  1394. pMhit->SetXint(-999);
  1395. pMhit->SetYint(-999);
  1396. pMhit->SetZint(-999);
  1397. }
  1398. }
  1399. if(rootoutput) {
  1400. if(pMhit->GetZint()!= -999) {
  1401. eventCanvas2->cd();
  1402. TMarker *mrk3 = new TMarker(scos, pMhit->GetZint(), 6);
  1403. mrk3->SetMarkerColor(2);
  1404. mrk3->Draw("SAME");
  1405. }
  1406. }
  1407. okcounter = okcounter + 2;
  1408. }
  1409. return kTRUE;
  1410. // fiterrp = sqrt(fiterrp2);
  1411. // fiterrm = sqrt(fiterrm2);
  1412. }
  1413. // -------- ZFinder2 --------------------------------------------
  1414. Bool_t CbmSttHelixTrackFitter::ZFinder2(CbmSttTrack* pTrack, Int_t pidHypo) {
  1415. // CHANGED Scosl
  1416. if(!pTrack) return 0;
  1417. Int_t hitcounter = pTrack->GetNofHits();
  1418. // cut on number of hits
  1419. if(hitcounter > 30) {
  1420. // cout << "more than 30 hits" << endl;
  1421. // pTrack->GetParamLast()->SetX(-999);
  1422. // pTrack->GetParamLast()->SetY(-999);
  1423. // // Double_t newZ = -999.; // CHECK da cambiare
  1424. // // pTrack->GetParamLast()->SetZ(newZ);
  1425. // pTrack->GetParamLast()->SetTx(-999);
  1426. // // Double_t newTheta = -999.; // CHECK da cambiare
  1427. // // pTrack->GetParamLast()->SetTy(newTheta);
  1428. // pTrack->GetParamLast()->SetQp(0.);
  1429. return 0;
  1430. }
  1431. if(hitcounter < 5) {
  1432. // cout << "less than 5 hits" << endl;
  1433. // pTrack->GetParamLast()->SetX(-999);
  1434. // pTrack->GetParamLast()->SetY(-999);
  1435. // // Double_t newZ = -999.; // CHECK da cambiare
  1436. // // pTrack->GetParamLast()->SetZ(newZ);
  1437. // pTrack->GetParamLast()->SetTx(-999);
  1438. // // Double_t newTheta = -999.; // CHECK da cambiare
  1439. // // pTrack->GetParamLast()->SetTy(newTheta);
  1440. // pTrack->GetParamLast()->SetQp(0.);
  1441. return 0;
  1442. }
  1443. ZPointsArray = new TObjArray(2*hitcounter);
  1444. // SCOSL ======
  1445. // phi0
  1446. TVector3 *v0;
  1447. Double_t Phi0;
  1448. // ============
  1449. // ZFIT =======
  1450. if(hitcounter == 0) return kFALSE;
  1451. Double_t Sxx, Sx, Sz, Sxz, S1z;
  1452. Double_t Detz = 0.;
  1453. Double_t fitm, fitp;
  1454. Double_t sigz = 1.; // CHECK
  1455. Sx = 0.;
  1456. Sz = 0.;
  1457. Sxx = 0.;
  1458. Sxz = 0.;
  1459. S1z = 0.;
  1460. // ============
  1461. TVector3 *tofit, *tofit2;
  1462. // centre of curvature
  1463. Double_t x_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY());
  1464. Double_t y_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY());
  1465. // radius of curvature
  1466. Double_t R = pTrack->GetParamLast()->GetTx();
  1467. Int_t wireOk = 0;
  1468. for (Int_t i = 0; i < hitcounter; i++) {
  1469. // get index of hit
  1470. Int_t iHit = pTrack->GetHitIndex(i);
  1471. // get hit
  1472. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  1473. if(pMhit == NULL) continue;
  1474. Int_t refindex = pMhit->GetRefIndex();
  1475. // get point
  1476. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  1477. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  1478. TVector3 wiredirection2;
  1479. wiredirection2 = 75. * wiredirection;
  1480. TVector3 cenposition(pMhit->GetX(), pMhit->GetY(), 0.); // CHECK! z = 35!!
  1481. TVector3 min, max;
  1482. min = cenposition - wiredirection2;
  1483. max = cenposition + wiredirection2;
  1484. // first extremity
  1485. Double_t x_1= min.X();
  1486. Double_t y_1= min.Y();
  1487. Double_t z_1= min.Z();
  1488. // second extremity
  1489. Double_t x_2= max.X();
  1490. Double_t y_2= max.Y();
  1491. Double_t z_2= max.Z();
  1492. Double_t rcur = pMhit->GetIsochrone();
  1493. if(wiredirection != TVector3(0.,0.,1.))
  1494. {
  1495. wireOk++;
  1496. Double_t a = -999;
  1497. Double_t b = -999;
  1498. Double_t x1 = -9999.;
  1499. Double_t y1 = -9999.;
  1500. Double_t x2 = -9999.;
  1501. Double_t y2 = -9999.;
  1502. // intersection point between the reconstructed
  1503. // circumference and the line joining the centres
  1504. // of the reconstructed circle and the i_th drift circle
  1505. if(fabs(x_2-x_1)>0.0001) {
  1506. a =(y_2-y_1)/(x_2-x_1);
  1507. b =(y_1-a*x_1);
  1508. Double_t A = a*a+1;
  1509. Double_t B = x_0+a*y_0-a*b;
  1510. Double_t C = x_0*x_0+y_0*y_0+b*b-R*R-2*y_0*b;
  1511. if((B*B-A*C)>0) {
  1512. x1= (B+TMath::Sqrt(B*B-A*C))/A;
  1513. x2= (B-TMath::Sqrt(B*B-A*C))/A;
  1514. y1=a*x1+b;
  1515. y2=a*x2+b;
  1516. }
  1517. }
  1518. else if(fabs(y_2-y_1)>0.0001) {
  1519. Double_t A = 1;
  1520. Double_t B = y_0;
  1521. Double_t C = y_0*y_0 +(x_1-x_0)*(x_1-x_0) -R*R;
  1522. if((B*B-A*C)>0) {
  1523. y1= (B+TMath::Sqrt(B*B-A*C))/A;
  1524. y2= (B-TMath::Sqrt(B*B-A*C))/A;
  1525. x1=x2=x_1;
  1526. }
  1527. }
  1528. //x1 and x2 are the 2 intersection points
  1529. Double_t d1=TMath::Sqrt((x1-cenposition.X())*(x1-cenposition.X())+
  1530. (y1-cenposition.Y())*(y1-cenposition.Y()));
  1531. Double_t d2=TMath::Sqrt((x2-cenposition.X())*(x2-cenposition.X())+
  1532. (y2-cenposition.Y())*(y2-cenposition.Y()));
  1533. Double_t x_ = x1;
  1534. Double_t y_ = y1;
  1535. // the intersection point nearest to the drift circle's centre is taken
  1536. if(d2<d1) {x_=x2;y_=y2;}
  1537. // now we need to find the actual centre of the drift circle,
  1538. // by translating the drift circle until it becomes tangent
  1539. // to the reconstructed circle.
  1540. // Two solutions are possible (left rigth abiguity),
  1541. // they are both kept, only the following zed fit will discard the wrong ones.
  1542. // Using the parametric equation of the 3d-straigth line and taking the
  1543. // x points just obtained, the zed coordinate of the skewed tube centre is calculated.
  1544. //solving the equation to find out the centre of the tangent circle
  1545. Double_t A = a*a+1;
  1546. Double_t B = -(a*b-a*y_-x_);
  1547. Double_t C = x_*x_+ y_*y_+b*b-2*b*y_-rcur*rcur;
  1548. if((B*B-A*C)>0) {
  1549. x1= (B+TMath::Sqrt(B*B-A*C))/A;
  1550. x2= (B-TMath::Sqrt(B*B-A*C))/A;
  1551. y1=a*x1+b;
  1552. y2=a*x2+b;
  1553. }
  1554. d1=TMath::Sqrt((x1-cenposition.X())*(x1-cenposition.X())+(y1-cenposition.Y())*(y1-cenposition.Y()));
  1555. d2=TMath::Sqrt((x2-cenposition.X())*(x2-cenposition.X())+(y2-cenposition.Y())*(y2-cenposition.Y()));
  1556. Double_t xcen0=x1;
  1557. Double_t xcen1=x2;
  1558. Double_t ycen0=y1;
  1559. Double_t ycen1=y2;
  1560. if(d2<d1) { // z2 contains the points nearest (in x-y) to the initial centre of the skewed tube
  1561. xcen0=x2;
  1562. xcen1=x1;
  1563. ycen0=y2;
  1564. ycen1=y1;
  1565. }
  1566. // zed association
  1567. if(fabs(x_2-x_1)<0.001) return kFALSE;
  1568. Double_t t_ =(xcen0-x_1)/(x_2-x_1); // x= a_x*t + x_1 [t=1 x=x_2]
  1569. Double_t z_ =(z_2-z_1)*t_ +z_1; // z= a_z*t + z_1 [t=1 z=z_2]
  1570. Double_t t_bis =(xcen1-x_1)/(x_2-x_1); // from x_'s (the 2 solutions of the 2nd order equation)
  1571. Double_t z_bis =(z_2-z_1)*t_bis +z_1; // and the 2 parametric equations the z coord. are obtained
  1572. tofit = new TVector3(xcen0,ycen0,z_);
  1573. ZPointsArray->Add(tofit);
  1574. tofit2 = new TVector3(xcen1,ycen1,z_bis);
  1575. ZPointsArray->Add(tofit2);
  1576. // FIRST CHOICE
  1577. //====================
  1578. // scosl
  1579. Double_t x0;
  1580. Double_t y0;
  1581. if(wireOk == 1) {
  1582. if(tofit != NULL) {
  1583. // phi0
  1584. v0 = new TVector3(tofit->X(), tofit->Y(), tofit->Z());
  1585. }
  1586. else if(tofit2 != NULL) {
  1587. v0 = new TVector3(tofit2->X(), tofit2->Y(), tofit2->Z());
  1588. }
  1589. Phi0 = TMath::ATan2((v0->Y() - y_0),(v0->X() - x_0));
  1590. // CHECK
  1591. // we are using the first digi for the arc length calculation
  1592. // but this may be wrong
  1593. x0 = v0->X();
  1594. y0 = v0->Y();
  1595. }
  1596. TVector3 vi(tofit->X(), tofit->Y(), tofit->Z());
  1597. // Double_t scos = R*TMath::ATan2((vi.Y() - y0)*TMath::Cos(Phi0) - (vi.X() - x0)*TMath::Sin(Phi0) , R + (vi.X() - x0) * TMath::Cos(Phi0) + (vi.Y()-y0) * TMath::Sin(Phi0));
  1598. Double_t scos = R*(TMath::ATan2(R*TMath::Sin(Phi0) - (vi.Y() - y0), R * TMath::Cos(Phi0) - (vi.X() - x0)) - Phi0);
  1599. //====================
  1600. if(rootoutput) {
  1601. eventCanvas2->cd();
  1602. TMarker *mrk = new TMarker(scos, tofit->Z(), 6);
  1603. mrk->Draw("SAME");
  1604. }
  1605. //====================
  1606. // zfit
  1607. //
  1608. Sx = Sx + (scos/(sigz * sigz));
  1609. Sz = Sz + (tofit->Z()/(sigz * sigz));
  1610. Sxz = Sxz + ((scos * tofit->Z())/(sigz * sigz));
  1611. Sxx = Sxx + ((scos * scos)/(sigz * sigz));
  1612. S1z = S1z + 1/(sigz * sigz);
  1613. //====================
  1614. // SECOND CHOICE
  1615. //====================
  1616. // scosl
  1617. vi.SetXYZ(tofit2->X(), tofit2->Y(), tofit2->Z());
  1618. // scos = R*TMath::ATan2((vi.Y() - y0)*TMath::Cos(Phi0) - (vi.X() - x0)*TMath::Sin(Phi0) , R + (vi.X() - x0) * TMath::Cos(Phi0) + (vi.Y()-y0) * TMath::Sin(Phi0));
  1619. scos = R*(TMath::ATan2(R*TMath::Sin(Phi0) - (vi.Y() - y0), R * TMath::Cos(Phi0) - (vi.X() - x0)) - Phi0);
  1620. //====================
  1621. //====================
  1622. // zfit
  1623. //
  1624. Sx = Sx + (scos/(sigz * sigz));
  1625. Sz = Sz + (tofit2->Z()/(sigz * sigz));
  1626. Sxz = Sxz + ((scos * tofit2->Z())/(sigz * sigz));
  1627. Sxx = Sxx + ((scos * scos)/(sigz * sigz));
  1628. S1z = S1z + 1/(sigz * sigz);
  1629. //====================
  1630. if(rootoutput) {
  1631. eventCanvas2->cd();
  1632. TMarker *mrk2 = new TMarker(scos, tofit2->Z(), 6);
  1633. mrk2->Draw("SAME");
  1634. }
  1635. }
  1636. }
  1637. cout << "skewed: " << wireOk << endl;
  1638. if(wireOk < 2) return kFALSE;
  1639. Detz = S1z*Sxx - Sx*Sx;
  1640. if(Detz == 0) {
  1641. return kFALSE;
  1642. }
  1643. fitp = (1/Detz)*(Sxx*Sz - Sx*Sxz);
  1644. fitm = (1/Detz)*(S1z*Sxz - Sx*Sz);
  1645. // fiterrp2 = (1/Detz)*Sxx;
  1646. // fiterrm2 = (1/Detz)*S1z;
  1647. if(rootoutput) {
  1648. eventCanvas2->cd();
  1649. TLine *line = new TLine(-20, -20*fitm + fitp, 20, (20*fitm + fitp));
  1650. line->Draw("SAME");
  1651. }
  1652. // Double_t chi2z;
  1653. // chi2z = 0.;
  1654. // for(Int_t i=0; i < hitcounter; i++) {
  1655. // TVector3 * vi= (TVector3 *) ZArray->At(i);
  1656. // chi2z = chi2z + pow(((vi->Z()-(fitp+fitm*scosl->At(i)))/sigz), 2);
  1657. // // RESIDUALS
  1658. // // if(pow(((vi->Z()-(fitp+fitm*scosl[i]))/sigz), 2)>10) continue;
  1659. // // bestz[ctbest]=vi->Z();
  1660. // // bests[ctbest]=scosl[i];
  1661. // // ctbest++;
  1662. // }
  1663. // y = m*x + p
  1664. TVector2 outz(fitm, fitp);
  1665. Int_t counter = 0;
  1666. if(fitm == 0. && fitp == 0.) return kFALSE;
  1667. if( wireOk < 2) return kFALSE;
  1668. wireOk = 0;
  1669. Int_t okcounter = 0;
  1670. for(Int_t i = 0; i < (2*hitcounter); i+=2) {
  1671. // get index of hit
  1672. // cout << i << " counter: " << counter << endl;
  1673. Int_t iHit = pTrack->GetHitIndex(counter);
  1674. counter++;
  1675. // get hit
  1676. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  1677. Int_t refindex = pMhit->GetRefIndex();
  1678. // get point
  1679. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  1680. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  1681. if(wiredirection == TVector3(0.,0.,1.)) continue;
  1682. wireOk++;
  1683. sigz = 1.; // CHECK
  1684. Double_t x0;
  1685. Double_t y0;
  1686. if(wireOk==1) {
  1687. TVector3 *vi = (TVector3*) ZPointsArray->At(okcounter);
  1688. // phi0
  1689. v0->SetXYZ(vi->X(), vi->Y(), vi->Z());
  1690. Phi0 = TMath::ATan2((v0->Y() - y_0),(v0->X() - x_0));
  1691. // CHECK
  1692. // we are using the first digi for the arc length calculation
  1693. // but this may be wrong
  1694. x0 = v0->X();
  1695. y0 = v0->Y();
  1696. }
  1697. // FIRST CHOICE
  1698. TVector3 *vi = (TVector3*) ZPointsArray->At(okcounter);
  1699. if(vi == NULL) continue;
  1700. Double_t scos = R*(TMath::ATan2(R*TMath::Sin(Phi0) - (vi->Y() - y0), R * TMath::Cos(Phi0) - (vi->X() - x0)) - Phi0);
  1701. Bool_t fitdone = kFALSE;
  1702. Double_t distfirst = pow(((vi->Z() - (outz.Y() + outz.X() * scos))/sigz), 2);
  1703. if(distfirst < 10) {
  1704. pMhit->SetXint(vi->X());
  1705. pMhit->SetYint(vi->Y());
  1706. pMhit->SetZint(vi->Z());
  1707. fitdone = kTRUE;
  1708. }
  1709. // SECOND CHOICE
  1710. vi = (TVector3*) ZPointsArray->At(okcounter+1);
  1711. if(vi == NULL) continue;
  1712. scos = R*(TMath::ATan2(R*TMath::Sin(Phi0) - (vi->Y() - y0), R * TMath::Cos(Phi0) - (vi->X() - x0)) - Phi0);
  1713. Double_t distsecond = pow(((vi->Z() - (outz.Y() + outz.X() * scos))/sigz), 2);
  1714. if(fitdone == kTRUE){
  1715. if(distsecond < 10 && distsecond < distfirst) {
  1716. pMhit->SetXint(vi->X());
  1717. pMhit->SetYint(vi->Y());
  1718. pMhit->SetZint(vi->Z());
  1719. }
  1720. }
  1721. else {
  1722. if (distsecond < 10) {
  1723. pMhit->SetXint(vi->X());
  1724. pMhit->SetYint(vi->Y());
  1725. pMhit->SetZint(vi->Z());
  1726. fitdone = kTRUE;
  1727. }
  1728. else {
  1729. pMhit->SetXint(-999);
  1730. pMhit->SetYint(-999);
  1731. pMhit->SetZint(-999);
  1732. }
  1733. }
  1734. if(rootoutput) {
  1735. if(pMhit->GetZint()!= -999) {
  1736. eventCanvas2->cd();
  1737. TMarker *mrk3 = new TMarker(scos, pMhit->GetZint(), 6);
  1738. mrk3->SetMarkerColor(2);
  1739. mrk3->Draw("SAME");
  1740. }
  1741. }
  1742. okcounter = okcounter + 2;
  1743. }
  1744. return kTRUE;
  1745. // fiterrp = sqrt(fiterrp2);
  1746. // fiterrm = sqrt(fiterrm2);
  1747. }
  1748. // ----- Zfit ----------------------------------------
  1749. Int_t CbmSttHelixTrackFitter::Zfit(CbmSttTrack* pTrack, Int_t pidHypo) {
  1750. // fEventCounter++;
  1751. if(!pTrack) return 0;
  1752. // TVector2 *position = NULL;
  1753. Int_t hitcounter = pTrack->GetNofHits();
  1754. // cut on number of hits
  1755. // if(hitcounter > 30) return 0;
  1756. if(hitcounter < 5) return 0;
  1757. // CHECK: ATTENTION
  1758. // refit for error correction missing
  1759. // SCOSL ======
  1760. // phi0
  1761. TVector3 * v0;
  1762. Double_t Phi0;
  1763. // ============
  1764. Double_t Sxx, Sx, Sz, Sxz, S1z;
  1765. Double_t Detz = 0.;
  1766. Double_t fitm, fitp;
  1767. Double_t sigz = 1.; // CHECK
  1768. Sx = 0.;
  1769. Sz = 0.;
  1770. Sxx = 0.;
  1771. Sxz = 0.;
  1772. S1z = 0.;
  1773. // centre of curvature
  1774. Double_t x_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY());
  1775. Double_t y_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY());
  1776. // radius of curvature
  1777. Double_t R = pTrack->GetParamLast()->GetTx();
  1778. Int_t counter = 0;
  1779. Int_t wireOk = 0;
  1780. for (Int_t i = 0; i < hitcounter; i++) {
  1781. // get index of hit
  1782. Int_t iHit = pTrack->GetHitIndex(i);
  1783. // get hit
  1784. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  1785. if ( ! pMhit ) continue;
  1786. if(pMhit->GetXint() == -999 || pMhit->GetYint() == -999 || pMhit->GetZint() == -999) continue; // CHECK
  1787. Int_t refindex = pMhit->GetRefIndex();
  1788. // get point
  1789. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  1790. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  1791. if(wiredirection == TVector3(0.,0.,1.)) continue;
  1792. counter++;
  1793. // SCOSL
  1794. Double_t x0;
  1795. Double_t y0;
  1796. wireOk++;
  1797. if(wireOk == 1) {
  1798. TVector3 *vi = new TVector3(pMhit->GetXint(), pMhit->GetYint(), pMhit->GetZint());
  1799. // phi0
  1800. v0 = new TVector3(vi->X(), vi->Y(), vi->Z());
  1801. Phi0 = TMath::ATan2((v0->Y() - y_0),(v0->X() - x_0));
  1802. // CHECK
  1803. // we are using the first digi for the arc length calculation
  1804. // but this may be wrong
  1805. x0 = v0->X();
  1806. y0 = v0->Y();
  1807. }
  1808. TVector3 *vi = new TVector3(pMhit->GetXint(), pMhit->GetYint(), pMhit->GetZint());
  1809. Double_t scos = R*TMath::ATan2((pMhit->GetYint() - y0)*TMath::Cos(Phi0) - (pMhit->GetXint() - x0)*TMath::Sin(Phi0) , R + (pMhit->GetXint() - x0) * TMath::Cos(Phi0) + (pMhit->GetYint()-y0) * TMath::Sin(Phi0));
  1810. Sx = Sx + (scos /(sigz * sigz));
  1811. Sz = Sz + (vi->Z()/(sigz * sigz));
  1812. Sxz = Sxz + ((scos *vi->Z())/(sigz * sigz));
  1813. Sxx = Sxx + ((scos * scos)/(sigz * sigz));
  1814. S1z = S1z + 1/(sigz * sigz);
  1815. }
  1816. if(counter == 0) return 0;
  1817. Detz = S1z*Sxx - Sx*Sx;
  1818. if(Detz == 0) {
  1819. return 0;
  1820. }
  1821. fitp = (1/Detz)*(Sxx*Sz - Sx*Sxz);
  1822. fitm = (1/Detz)*(S1z*Sxz - Sx*Sz);
  1823. // cout << "fit: " << fitp << " " << fitm << " " << Detz << endl;
  1824. // fiterrp2 = (1/Detz)*Sxx;
  1825. // fiterrm2 = (1/Detz)*S1z;
  1826. // Double_t chi2z;
  1827. // chi2z = 0.;
  1828. // for(Int_t i=0; i < zcounter; i++) {
  1829. // TVector3 * vi= (TVector3 *) ZArray->At(i);
  1830. // chi2z = chi2z + pow(((vi->Z()-(fitp+fitm*scosl->At(i)))/sigz), 2);
  1831. // // RESIDUALS
  1832. // // if(pow(((vi->Z()-(fitp+fitm*scosl[i]))/sigz), 2)>10) continue;
  1833. // // bestz[ctbest]=vi->Z();
  1834. // // bests[ctbest]=scosl[i];
  1835. // // ctbest++;
  1836. // }
  1837. // y = m*x + p
  1838. TVector2 outz(fitm, fitp);
  1839. pTrack->GetParamLast()->SetZ(fitp); // z (adesso fitp) CHECK
  1840. // pTrack->GetParamLast()->SetTy((TMath::Pi()/2.) - TMath::ATan(fitm)); // theta
  1841. pTrack->GetParamLast()->SetTy(fitm); // CHECK da cambiare con theta
  1842. if(rootoutput) {
  1843. eventCanvas2->cd();
  1844. TLine *line2 = new TLine(-20, -20*fitm + fitp, 20, (20*fitm + fitp));
  1845. line2->SetLineColor(3);
  1846. line2->Draw("SAME");
  1847. }
  1848. return 1;
  1849. // fiterrp = sqrt(fiterrp2);
  1850. // fiterrm = sqrt(fiterrm2);
  1851. }
  1852. // -------------------------------------------------------------------------------
  1853. // ----- Zfit2 ----------------------------------------
  1854. Int_t CbmSttHelixTrackFitter::Zfit2(CbmSttTrack* pTrack, Int_t pidHypo) {
  1855. // fEventCounter++;
  1856. if(!pTrack) return 0;
  1857. // TVector2 *position = NULL;
  1858. Int_t hitcounter = pTrack->GetNofHits();
  1859. // cut on number of hits
  1860. // if(hitcounter > 30) return 0;
  1861. if(hitcounter < 5) return 0;
  1862. // CHECK: ATTENTION
  1863. // refit for error correction missing
  1864. // if(ZArray==NULL || (xy.X() == 0 && xy.Y() == 0 && xy.Z() == 0)) return TVector2(0.,0.);
  1865. // if(ZArray->GetEntries() <= 1) return TVector2(0.,0.);
  1866. // SCOSL ======
  1867. // phi0
  1868. TVector3 * v0;
  1869. Double_t Phi0;
  1870. // ============
  1871. Double_t Sxx, Sx, Sz, Sxz, S1z;
  1872. Double_t Detz = 0.;
  1873. Double_t fitm, fitp;
  1874. Double_t sigz = 1.; // CHECK
  1875. Sx = 0.;
  1876. Sz = 0.;
  1877. Sxx = 0.;
  1878. Sxz = 0.;
  1879. S1z = 0.;
  1880. // centre of curvature
  1881. Double_t x_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY());
  1882. Double_t y_0 = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY());
  1883. // radius of curvature
  1884. Double_t R = pTrack->GetParamLast()->GetTx();
  1885. Int_t counter = 0;
  1886. Int_t wireOk = 0;
  1887. for (Int_t i = 0; i < hitcounter; i++) {
  1888. // get index of hit
  1889. Int_t iHit = pTrack->GetHitIndex(i);
  1890. // get hit
  1891. CbmSttHit *pMhit = (CbmSttHit*) fHitArray->At(iHit);
  1892. if ( ! pMhit ) continue;
  1893. if(pMhit->GetXint() == -999 || pMhit->GetYint() == -999 || pMhit->GetZint() == -999) continue; // CHECK
  1894. Int_t refindex = pMhit->GetRefIndex();
  1895. // get point
  1896. CbmSttPoint *iPoint = (CbmSttPoint*) fPointArray->At(refindex);
  1897. TVector3 wiredirection(iPoint->GetXWireDirection(), iPoint->GetYWireDirection(), iPoint->GetZWireDirection());
  1898. if(wiredirection == TVector3(0.,0.,1.)) continue;
  1899. counter++;
  1900. // SCOSL
  1901. Double_t x0;
  1902. Double_t y0;
  1903. wireOk++;
  1904. if(wireOk == 1) {
  1905. TVector3 *vi = new TVector3(pMhit->GetXint(), pMhit->GetYint(), pMhit->GetZint());
  1906. // phi0
  1907. v0 = new TVector3(vi->X(), vi->Y(), vi->Z());
  1908. Phi0 = TMath::ATan2((v0->Y() - y_0),(v0->X() - x_0));
  1909. // CHECK
  1910. // we are using the first digi for the arc length calculation
  1911. // but this may be wrong
  1912. x0 = v0->X();
  1913. y0 = v0->Y();
  1914. }
  1915. TVector3 *vi = new TVector3(pMhit->GetXint(), pMhit->GetYint(), pMhit->GetZint());
  1916. // Double_t scos = R*TMath::ATan2((pMhit->GetYint() - y0)*TMath::Cos(Phi0) - (pMhit->GetXint() - x0)*TMath::Sin(Phi0) , R + (pMhit->GetXint() - x0) * TMath::Cos(Phi0) + (pMhit->GetYint()-y0) * TMath::Sin(Phi0));
  1917. Double_t scos = R*(TMath::ATan2(R*TMath::Sin(Phi0) - (pMhit->GetYint() - y0), R * TMath::Cos(Phi0) - (pMhit->GetXint() - x0)) - Phi0);
  1918. Sx = Sx + (scos /(sigz * sigz));
  1919. Sz = Sz + (vi->Z()/(sigz * sigz));
  1920. Sxz = Sxz + ((scos *vi->Z())/(sigz * sigz));
  1921. Sxx = Sxx + ((scos * scos)/(sigz * sigz));
  1922. S1z = S1z + 1/(sigz * sigz);
  1923. }
  1924. if(counter == 0) return 0;
  1925. Detz = S1z*Sxx - Sx*Sx;
  1926. if(Detz == 0) {
  1927. return 0;
  1928. }
  1929. fitp = (1/Detz)*(Sxx*Sz - Sx*Sxz);
  1930. fitm = (1/Detz)*(S1z*Sxz - Sx*Sz);
  1931. // cout << "fit: " << fitp << " " << fitm << " " << Detz << endl;
  1932. // fiterrp2 = (1/Detz)*Sxx;
  1933. // fiterrm2 = (1/Detz)*S1z;
  1934. // Double_t chi2z;
  1935. // chi2z = 0.;
  1936. // for(Int_t i=0; i < zcounter; i++) {
  1937. // TVector3 * vi= (TVector3 *) ZArray->At(i);
  1938. // chi2z = chi2z + pow(((vi->Z()-(fitp+fitm*scosl->At(i)))/sigz), 2);
  1939. // // RESIDUALS
  1940. // // if(pow(((vi->Z()-(fitp+fitm*scosl[i]))/sigz), 2)>10) continue;
  1941. // // bestz[ctbest]=vi->Z();
  1942. // // bests[ctbest]=scosl[i];
  1943. // // ctbest++;
  1944. // }
  1945. // y = m*x + p
  1946. TVector2 outz(fitm, fitp);
  1947. pTrack->GetParamLast()->SetZ(fitp); // z (adesso fitp) CHECK
  1948. // pTrack->GetParamLast()->SetTy((TMath::Pi()/2.) - TMath::ATan(fitm)); // theta
  1949. pTrack->GetParamLast()->SetTy(fitm); // CHECK da cambiare con theta
  1950. if(rootoutput) {
  1951. eventCanvas2->cd();
  1952. TLine *line2 = new TLine(-20, -20*fitm + fitp, 20, (20*fitm + fitp));
  1953. line2->SetLineColor(3);
  1954. line2->Draw("SAME");
  1955. }
  1956. return 1;
  1957. // fiterrp = sqrt(fiterrp2);
  1958. // fiterrm = sqrt(fiterrm2);
  1959. }
  1960. // ----
  1961. // ----------------------------------------------------
  1962. void CbmSttHelixTrackFitter::Extrapolate(CbmSttTrack* track, Double_t r, FairTrackParam *param )
  1963. {
  1964. cout << "-W- CbmSttMinuitTrackFitter::Extrapolate: Not yet implemented, sorry!"
  1965. << endl;
  1966. }
  1967. // // ----- Private method AddHOT -----------------------------------------
  1968. // CbmSttHOT* CbmSttHelixTrackFitter::AddHOT(Double_t x, Double_t y, Double_t z, Int_t hitindex, Int_t pointindex, Int_t trackindex)
  1969. // {
  1970. // TClonesArray&
  1971. // clref = *fHotArray;
  1972. // Int_t
  1973. // size = clref.GetEntriesFast();
  1974. // // cout << "filling HOT" << endl;
  1975. // return new(clref[size]) CbmSttHOT(x, y, z, hitindex, pointindex, trackindex);
  1976. // }
  1977. // // -------------------------------------------------------------------------
  1978. void CbmSttHelixTrackFitter::ResetMArray() {
  1979. for(Int_t i = 0; i < 100; i++) marray.AddAt(-999, i);
  1980. }
  1981. Int_t CbmSttHelixTrackFitter::MinuitFit(CbmSttTrack* pTrack, Int_t pidHypo)
  1982. {
  1983. cout << "MINUIT FIT " << pTrack->GetNofHits() << endl;
  1984. fEventCounter++;
  1985. Double_t hitcounter = pTrack->GetNofHits();
  1986. Double_t rstart = pTrack->GetParamLast()->GetTx();
  1987. Double_t xcstart = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY());
  1988. Double_t ycstart = (pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY());
  1989. TMinuit minimizer(3);
  1990. cout << "*******MINUIT********" << endl;
  1991. cout << "D SEED: " << pTrack->GetParamLast()->GetX() << endl;
  1992. cout << "PHI SEED: " << pTrack->GetParamLast()->GetY() << endl;
  1993. cout << "R SEED: " << pTrack->GetParamLast()->GetTx() << endl;
  1994. cout << "********************" << endl;
  1995. minimizer.SetFCN(fcnHelix);
  1996. // minimizer.SetErrorDef(1); // ???
  1997. minimizer.DefineParameter(0, "xc", xcstart, 0.1, -3000., 3000.); // ???
  1998. minimizer.DefineParameter(1, "yc", ycstart, 0.1, -3000., 3000.); // ??? LIMITS ???
  1999. minimizer.DefineParameter(2, "r", rstart, 0.1, 0., 3000.); // ???
  2000. cout << "xcstart: " << xcstart << " ycxtart: " << ycstart << " rstart: " << rstart << endl;
  2001. minimizer.SetObjectFit(this);
  2002. minimizer.SetPrintLevel(-1);
  2003. minimizer.SetMaxIterations(500);
  2004. minimizer.Migrad();
  2005. Double_t chisquare, resultsRadial[3], errorsRadial[3];
  2006. minimizer.GetParameter(0, resultsRadial[0], errorsRadial[0]);
  2007. minimizer.GetParameter(1, resultsRadial[1], errorsRadial[1]);
  2008. minimizer.GetParameter(2, resultsRadial[2], errorsRadial[2]);
  2009. // minimizer.Eval(3, NULL, chisquare, resultsRadial, 0); // ???
  2010. cout << "xc: " << resultsRadial[0] << endl;
  2011. cout << "yc: " << resultsRadial[1] << endl;
  2012. cout << "R: " << resultsRadial[2] << endl;
  2013. Double_t phi = TMath::ATan2(resultsRadial[1], resultsRadial[0]); // CHECK
  2014. Double_t d;
  2015. d = ((resultsRadial[0] + resultsRadial[1]) - resultsRadial[2] *(TMath::Cos(phi) + TMath::Sin(phi)))/(TMath::Cos(phi) + TMath::Sin(phi)); // CHECK
  2016. pTrack->SetChi2Rad(chisquare);
  2017. pTrack->SetNDF(fTrack->GetNofHits());
  2018. pTrack->GetParamLast()->SetX(d);
  2019. pTrack->GetParamLast()->SetY(phi);
  2020. // pTrack->GetParamLast()->SetZ(z0);
  2021. pTrack->GetParamLast()->SetTx(resultsRadial[2]);
  2022. // pTrack->GetParamLast()->SetTy(alpha);
  2023. pTrack->GetParamLast()->SetQp(0.);
  2024. if(rootoutput) {
  2025. eventCanvas->cd();
  2026. TArc *fitarc = new TArc(((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * cos(pTrack->GetParamLast()->GetY())), ((pTrack->GetParamLast()->GetX() + pTrack->GetParamLast()->GetTx()) * sin(pTrack->GetParamLast()->GetY())), pTrack->GetParamLast()->GetTx());
  2027. fitarc->SetLineColor(3);
  2028. fitarc->Draw("SAME");
  2029. eventCanvas->Update();
  2030. eventCanvas->Modified();
  2031. }
  2032. return 1;
  2033. }
  2034. void fcnHelix(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
  2035. {
  2036. const CbmSttHelixTrackFitter *mama = (CbmSttHelixTrackFitter *)gMinuit->GetObjectFit();
  2037. CbmSttTrack *fTrack = mama->GetTrack();
  2038. CbmSttHit *currenthit = NULL;
  2039. Double_t chisq = 0;
  2040. Double_t delta = 0;
  2041. Int_t hitcounter = fTrack->GetNofHits();
  2042. Double_t xcur=0;
  2043. Double_t ycur=0;
  2044. for (Int_t i = 0; i < hitcounter; i++)
  2045. {
  2046. // get index of hit
  2047. Int_t iHit = fTrack->GetHitIndex(i);
  2048. // get hit
  2049. currenthit = mama->GetHitFromCollections(iHit);
  2050. if(!currenthit) continue;
  2051. if(currenthit->GetXint() == -999 || currenthit->GetYint() == -999) continue;
  2052. TVector3 wiredirection = currenthit->GetWireDirection();
  2053. if(wiredirection != TVector3(0.,0.,1.)) continue;
  2054. xcur = currenthit->GetXint();
  2055. ycur = currenthit->GetYint();
  2056. // cout <<"MINUIT: " << currenthit->GetXint() << " " << currenthit->GetYint() << endl;
  2057. delta =sqrt((xcur-par[0])*(xcur-par[0])+(ycur-par[1])*(ycur-par[1])) -par[2] ;
  2058. if(currenthit->GetIsochrone() == 0) chisq += (delta * delta * 12.);
  2059. else chisq += (delta*delta)/(currenthit->GetIsochrone() * currenthit->GetIsochrone() / 12.);
  2060. }
  2061. f = chisq;
  2062. }
  2063. CbmSttHit* CbmSttHelixTrackFitter::GetHitFromCollections(Int_t hitCounter) const
  2064. {
  2065. CbmSttHit
  2066. *retval = NULL;
  2067. Int_t
  2068. relativeCounter = hitCounter;
  2069. for (Int_t collectionCounter = 0; collectionCounter < fHitCollectionList.GetEntries(); collectionCounter++)
  2070. {
  2071. Int_t
  2072. size = ((TClonesArray *)fHitCollectionList.At(collectionCounter))->GetEntriesFast();
  2073. if (relativeCounter < size)
  2074. {
  2075. retval = (CbmSttHit*) ((TClonesArray *)fHitCollectionList.At(collectionCounter))->At(relativeCounter);
  2076. break;
  2077. }
  2078. else
  2079. {
  2080. relativeCounter -= size;
  2081. }
  2082. }
  2083. return retval;
  2084. }
  2085. ClassImp(CbmSttTrackFitter)