MpdTpcDedxTask.cxx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // -------------------------------------------------------------------------
  2. // ----- MpdTpcDedxTask source file -----
  3. // ----- Created 9/02/10 by A. Zinchenko -----
  4. // -------------------------------------------------------------------------
  5. /** MpdTpcDedxTask.cxx
  6. *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru>
  7. **
  8. ** dE/dx determination in MPD TPC
  9. **/
  10. #include "MpdTpcDedxTask.h"
  11. #include "MpdTpcKalmanTrack.h"
  12. #include "MpdTpcHit.h"
  13. #include "FairRootManager.h"
  14. #include <TFile.h>
  15. #include <TMath.h>
  16. #include <iostream>
  17. #include <set>
  18. using std::cout;
  19. using std::endl;
  20. using std::set;
  21. //__________________________________________________________________________
  22. MpdTpcDedxTask::MpdTpcDedxTask(const char *name, Int_t iVerbose )
  23. :FairTask(name, iVerbose)
  24. {
  25. fHistoDir = nullptr;
  26. fTracks = nullptr, fMCTracks = nullptr;
  27. }
  28. //__________________________________________________________________________
  29. MpdTpcDedxTask::~MpdTpcDedxTask()
  30. {
  31. //delete fKHits;
  32. //delete fTracks;
  33. //delete fTrackCand;
  34. }
  35. //__________________________________________________________________________
  36. InitStatus MpdTpcDedxTask::Init()
  37. {
  38. fTracks = 0x0;
  39. fTracks =(TClonesArray *) FairRootManager::Instance()->GetObject("ItsTrack");
  40. if (fTracks == 0x0) fTracks =(TClonesArray *) FairRootManager::Instance()->GetObject("TpcKalmanTrack");
  41. fHits0 = (TClonesArray *) FairRootManager::Instance()->GetObject("TpcHit");
  42. fHits = (TClonesArray *) FairRootManager::Instance()->GetObject("TpcRecPoint");
  43. fMCTracks =(TClonesArray *) FairRootManager::Instance()->GetObject("MCTrack");
  44. return kSUCCESS;
  45. }
  46. //__________________________________________________________________________
  47. void MpdTpcDedxTask::Reset()
  48. {
  49. ///
  50. }
  51. //__________________________________________________________________________
  52. void MpdTpcDedxTask::SetParContainers()
  53. {
  54. }
  55. //__________________________________________________________________________
  56. void MpdTpcDedxTask::Finish()
  57. {
  58. //Write();
  59. }
  60. //__________________________________________________________________________
  61. void MpdTpcDedxTask::Exec(Option_t * option)
  62. {
  63. const Double_t trunc = 0.7; // truncation parameter
  64. static Int_t eventCounter = 0;
  65. cout << " MpdTpcDedxTask event " << ++eventCounter << endl;
  66. Reset();
  67. Int_t nTracks = fTracks->GetEntriesFast();
  68. for (Int_t itr = 0; itr < nTracks; ++itr) {
  69. MpdTpcKalmanTrack *track = (MpdTpcKalmanTrack*) fTracks->UncheckedAt(itr);
  70. TClonesArray *hits = track->GetTrHits();
  71. Int_t nHits = hits->GetEntriesFast(), nOK = 0;
  72. Double_t *dedx = new Double_t [nHits];
  73. for (Int_t j = 0; j < nHits; ++j) {
  74. MpdKalmanHit *hit = (MpdKalmanHit*) hits->UncheckedAt(j);
  75. //cout << j << " " << hit->GetUniqueID() << " " << hit->GetDedx() << endl;
  76. if (hit->GetUniqueID() == 1) continue; // ITS hit
  77. if (hit->GetSignal() <= 0.) continue; // strange
  78. Double_t sig = hit->GetSignal();
  79. if (!fHits) {
  80. // For hit producer
  81. MpdTpcHit *thit = (MpdTpcHit*) fHits0->UncheckedAt(hit->GetIndex());
  82. Double_t x = thit->GetStep();
  83. x = TMath::Max (x, 0.4);
  84. x = TMath::Min (x, 10.0);
  85. sig /= (7.57541 * TMath::Power(x-0.292613,0.0160641) - 6.64079);
  86. } else {
  87. // For clusters: correct for track angles
  88. while (1) {
  89. MpdKalmanHit *hit1 = nullptr;
  90. if (j == 0) hit1 = (MpdKalmanHit*) hits->UncheckedAt(1);
  91. else hit1 = (MpdKalmanHit*) hits->UncheckedAt(j-1);
  92. Int_t isec = hit->GetDetectorID() % 1000000;
  93. Int_t isec1 = hit1->GetDetectorID() % 1000000;
  94. if (isec != isec1 && TMath::Abs(isec-isec1) != 12) {
  95. if (j == 0 || j == nHits - 1) break; // no correction
  96. hit1 = (MpdKalmanHit*) hits->UncheckedAt(j+1);
  97. isec1 = hit1->GetDetectorID() % 1000000;
  98. if (isec != isec1 && TMath::Abs(isec-isec1) != 12) break; // no correction
  99. }
  100. MpdTpcHit *thit = (MpdTpcHit*) fHits->UncheckedAt(hit->GetIndex());
  101. MpdTpcHit *thit1 = (MpdTpcHit*) fHits->UncheckedAt(hit1->GetIndex());
  102. //Double_t padh = thit->GetStep();
  103. Double_t dx = thit->GetLocalX() - thit1->GetLocalX();
  104. Double_t dz = thit->GetLocalZ() - thit1->GetLocalZ();
  105. Double_t dy = thit->GetLocalY() - thit1->GetLocalY();
  106. //Double_t tancros = dx / padh;
  107. //Double_t tandip = dz / padh;
  108. Double_t tancros = TMath::Abs (dx / dy);
  109. Double_t tandip = TMath::Abs (dz / dy);
  110. sig /= TMath::Sqrt (1 + tancros * tancros + tandip * tandip);
  111. //sig /= TMath::Power (1 + tancros*tancros + tandip*tandip, 0.2);
  112. //sig /= TMath::Sqrt (1 + tancros * tancros);
  113. break;
  114. }
  115. }
  116. if (fHits && sig > -800) dedx[nOK++] = sig; // threshold
  117. else if (!fHits) dedx[nOK++] = sig;
  118. hit->SetSignal(sig);
  119. }
  120. if (nOK == 0) continue;
  121. Int_t *indx = new Int_t [nOK];
  122. TMath::Sort(nOK,dedx,indx,kFALSE);
  123. Double_t sum = 0.;
  124. Int_t nTrunc = TMath::Nint (nOK * trunc);
  125. if (nTrunc == 0) nTrunc = 1;
  126. for (Int_t j = 0; j < nTrunc; ++j) sum += dedx[indx[j]];
  127. track->SetPartID (sum / nTrunc);
  128. delete [] dedx;
  129. delete [] indx;
  130. // Apply signal correction for the drift length
  131. if (fHits)
  132. //for (Int_t iter = 0; iter < 3; ++iter) DriftCorrection(track);
  133. for (Int_t iter = 0; iter < 1; ++iter) DriftCorrection(track);
  134. }
  135. }
  136. //__________________________________________________________________________
  137. void MpdTpcDedxTask::DriftCorrection(MpdTpcKalmanTrack *track)
  138. {
  139. // Signal correction for the drift length
  140. Double_t dedx = TMath::Log10 (track->GetDedx(6.036e-3)); // in kev
  141. //cout << dedx << " " << track->GetPartID() << endl;
  142. dedx = TMath::Min (dedx, 2.5);
  143. dedx = TMath::Max (dedx, 1.0);
  144. Double_t dedx2 = dedx * dedx;
  145. Double_t coef = -3.51299e-05 + 8.99592e-05*dedx -6.55681e-05*dedx2 + 1.25936e-05*dedx2*dedx;
  146. //coef = TMath::Min (coef, 0.0);
  147. TClonesArray *hits = track->GetTrHits();
  148. Int_t nhits = hits->GetEntriesFast();
  149. const Double_t trunc = 0.7; // truncation parameter
  150. set<Double_t> signals;
  151. for (Int_t ih = 0; ih < nhits; ++ih) {
  152. MpdKalmanHit *hit = (MpdKalmanHit*) hits->UncheckedAt(ih);
  153. if (hit->GetSignal() < -800) continue; // threshold
  154. Double_t sig = TMath::Log10(hit->GetSignal()*6.036e-3); // in keV
  155. //cout << ih << " " << " " << hit->GetMeas(1) << " " << sig << " ";
  156. //sig /= (1 + p01 * TMath::Abs(hit->GetMeas(1)) + p02 * hit->GetMeas(1) * hit->GetMeas(1));
  157. sig /= (1 + coef * hit->GetMeas(1) * hit->GetMeas(1));
  158. //cout << sig << endl;
  159. signals.insert(sig);
  160. }
  161. Int_t nTrunc = TMath::Nint (signals.size() * trunc);
  162. if (nTrunc == 0) nTrunc = 1;
  163. Int_t nok = 0;
  164. Double_t sum = 0;
  165. for (set<Double_t>::iterator sit = signals.begin(); sit != signals.end(); ++sit) {
  166. sum += TMath::Power (10,*sit) / 6.036e-3;
  167. ++nok;
  168. if (nok == nTrunc) break;
  169. }
  170. track->SetPartID(sum/nTrunc);
  171. //cout << track->GetPartID() << endl;
  172. }
  173. //__________________________________________________________________________
  174. void MpdTpcDedxTask::Write()
  175. {
  176. /// Write
  177. TFile histoFile("Vertex.root","RECREATE");
  178. Writedir2current(fHistoDir);
  179. histoFile.Close();
  180. }
  181. //__________________________________________________________________________
  182. void MpdTpcDedxTask::Writedir2current( TObject *obj )
  183. {
  184. /// Write
  185. if( !obj->IsFolder() ) obj->Write();
  186. else{
  187. TDirectory *cur = gDirectory;
  188. TDirectory *sub = cur->mkdir(obj->GetName());
  189. sub->cd();
  190. TList *listSub = ((TDirectory*)obj)->GetList();
  191. TIter it(listSub);
  192. while( TObject *obj1=it() ) Writedir2current(obj1);
  193. cur->cd();
  194. }
  195. }
  196. //__________________________________________________________________________
  197. ClassImp(MpdTpcDedxTask);