FairRoot/PandaRoot
PndXYResidualTask.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- PndXYResidualTaskT source file -----
10 // -------------------------------------------------------------------------
11 
12 #include "PndXYResidualTask.h"
13 
14 #include "FairLink.h" // for FairLink
15 #include "FairRootManager.h" // for FairRootManager
16 #include "FairTimeStamp.h" // for FairTimeStamp
17 #include "FairRunAna.h"
18 
19 #include "PndSdsHit.h"
20 
21 #include <iosfwd> // for ostream
22 #include "TClass.h" // for TClass
23 #include "TClonesArray.h" // for TClonesArray
24 
25 #include <iostream> // for operator<<, cout, ostream, etc
26 #include <iomanip>
27 #include <vector> // for vector
28 
30 {
31  return kSUCCESS;
32 }
33 
34 // ----- Public method Init --------------------------------------------
36 {
37 
38  FairRootManager* ioman = FairRootManager::Instance();
39  if ( ! ioman ) {
40  std::cout << "-E- PndXYResidualTaskT::Init: "
41  << "RootManager not instantiated!" << std::endl;
42  return kFATAL;
43  }
44 
45  // Create and register output array
46  fHitArray = (TClonesArray*)FairRootManager::Instance()->GetObject(fBranchName);
47  fTrackArray = (TClonesArray*)FairRootManager::Instance()->GetObject("MvdTrack");
48 
49  fMissingHitArray = FairRootManager::Instance()->Register("MvdMissingHit","PndSdsHit", "MVD", kTRUE);
50  fProjectedHitArray = FairRootManager::Instance()->Register("MvdProjectedHit","PndSdsHit", "MVD", kTRUE);
51  fGoodHitArray = FairRootManager::Instance()->Register("GoodHit","PndSdsHit", "MVD", kTRUE);
52 
53  //if(fVerbose>1) { Info("Init","Registering this branch: %s/%s",fFolder.Data(),fOutputBranch.Data()); }
54  //fOutputArray = ioman->Register(fOutputBranch, fInputArray->GetClass()->GetName(), fFolder, fPersistance);
55  fHc0c0 = new TH2D("fHc0c0", "fHc0c0", 200, -0.1, 0.1, 200, -0.1, 0.1);
56  fHc0c1 = new TH2D("fHc0c1", "fHc0c1", 200, -0.1, 0.1, 200, -0.1, 0.1);
57  fHc0c2 = new TH2D("fHc0c2", "fHc0c2", 200, -0.1, 0.1, 200, -0.1, 0.1);
58  fHc0c3 = new TH2D("fHc0c3", "fHc0c3", 200, -0.1, 0.1, 200, -0.1, 0.1);
59  fHc0c0cut = new TH2D("fHc0c0cut", "fHc0c0cut", 400, -0.02, 0.02, 400, -0.02, 0.02);
60  fHc0c1cut = new TH2D("fHc0c1cut", "fHc0c1cut", 400, -0.02, 0.02, 400, -0.02, 0.02);
61  fHc0c2cut = new TH2D("fHc0c2cut", "fHc0c2cut", 400, -0.02, 0.02, 400, -0.02, 0.02);
62  fHc0c3cut = new TH2D("fHc0c3cut", "fHc0c3cut", 400, -0.02, 0.02, 400, -0.02, 0.02);
63  fHMissingHits = new TH1D("fHMIssingHits", "MissingHits", 4, -0.5,3.5);
64 
65 
66  return kSUCCESS;
67 }
68 // -------------------------------------------------------------------------
69 
70 // ----- Public method Exec --------------------------------------------
71 void PndXYResidualTask::Exec(Option_t*)
72 {
73  SetVerbose(2);
74  if (fVerbose > 1 && ++fEntryNr % 1000 == 0) {
75  std::cout << "-I- PndXYResidualTask: Event " << fEntryNr << std::endl;
76  }
77  std::set<int> sensorIDs;
78  fMissingHitArray->Delete();
79  fProjectedHitArray->Delete();
80 
81  for (int i = 0; i < 4; i++)
82  sensorIDs.insert(i);
83 
84  if (fTrackArray->GetEntriesFast() > 0){
85  for (int i = 0; i < fTrackArray->GetEntriesFast(); i++){
86  PndTrack* myTrack = (PndTrack*)fTrackArray->At(i);
87  std::vector<PndTrackCandHit> hits = myTrack->GetTrackCandPtr()->GetSortedHits();
88  std::set<int> tempIDs = sensorIDs;
89  for (int iHits = 0; iHits < hits.size(); iHits++){
90  PndSdsHit* myHit = (PndSdsHit*)fHitArray->At(hits[iHits].GetIndex());
91  //std::cout << "HitValue: " << myHit->GetPosition().X() << "/" << myHit->GetPosition().Y()<< "/" << myHit->GetPosition().Z() << std::endl;
92 
93  TVector3 predicted = PropagateToZ(myTrack, myHit->GetZ());
94  //std::cout << "PredictedValue: " <<predicted.X() << "/" << predicted.Y()<< "/" << predicted.Z() << std::endl;
95  TVector3 res = predicted - myHit->GetPosition();
96  tempIDs.erase(myHit->GetSensorID());
97  if (myHit->GetSensorID() == 0) fHc0c0->Fill(res.X(), res.Y());
98  if (myHit->GetSensorID() == 1) fHc0c1->Fill(res.X(), res.Y());
99  if (myHit->GetSensorID() == 2) fHc0c2->Fill(res.X(), res.Y());
100  if (myHit->GetSensorID() == 3) fHc0c3->Fill(res.X(), res.Y());
101  if (myTrack->GetChi2() / myTrack->GetNDF() < 2){
102  if (myHit->GetSensorID() == 0) fHc0c0cut->Fill(res.X(), res.Y());
103  if (myHit->GetSensorID() == 1) fHc0c1cut->Fill(res.X(), res.Y());
104  if (myHit->GetSensorID() == 2) fHc0c2cut->Fill(res.X(), res.Y());
105  if (myHit->GetSensorID() == 3) fHc0c3cut->Fill(res.X(), res.Y());
106  }
107 // if (myTrack->GetChi2() / myTrack->GetNDF() < 2){
108 // PndSdsHit* goodHit = new ((*fGoodHitArray)[fGoodHitArray->GetEntriesFast()]) PndSdsHit(*myHit);
109 // TVector3 correction;
110 // TVector3 errorMHit;
111 // Int_t j = goodHit->GetSensorID();
112 // if (j == 0) correction.SetXYZ(-1.348e-3, -4.01e-3, 0);
113 // else if (j == 1) correction.SetXYZ(+4.97e-3, 4.978e-3, 0);
114 // else if (j == 2) correction.SetXYZ(-7.21e-3, 0.42e-3, 0);
115 // else if (j == 3) correction.SetXYZ(+3.556e-3, -7.569e-3, 0);
116 // errorMHit = goodHit->GetPosition() + correction;
117 // goodHit->SetPositionError(errorMHit);
118 // }
119 
120  }
121  if (tempIDs.size() > 0){
122  for (std::set<int>::iterator it = tempIDs.begin(); it != tempIDs.end(); it++){
123  fHMissingHits->Fill(*it);
124  int sensID = *it;
125  TVector3 missingHit = PropagateToZ(myTrack, 10 + 6 * sensID);
126  TVector3 errorMHit(0,0,0);
127  new ((*fMissingHitArray)[fMissingHitArray->GetEntriesFast()]) PndSdsHit(-1, *it, missingHit, errorMHit, -1, -1, -1, -1);
128  }
129  }
130  if (myTrack->GetChi2() / myTrack->GetNDF() < 2){
131  for (int j = 0; j < 4; j++){
132  TVector3 projectedHit = PropagateToZ(myTrack, 10 + 6 * j);
133 
134  TVector3 correction;
135  TVector3 errorMHit;
136  if (j == 0) correction.SetXYZ(-1.348e-3, -4.01e-3, 0);
137  else if (j == 1) correction.SetXYZ(+4.97e-3, 4.978e-3, 0);
138  else if (j == 2) correction.SetXYZ(-7.21e-3, 0.42e-3, 0);
139  else if (j == 3) correction.SetXYZ(+3.556e-3, -7.569e-3, 0);
140  errorMHit = projectedHit + correction;
141 
142 
143  new ((*fProjectedHitArray)[fProjectedHitArray->GetEntriesFast()]) PndSdsHit(-1, j, projectedHit, errorMHit, -1, -1, hits.size(), -1);
144 
145  }
146  }
147  }
148 
149  }
150 
151 }
152 
154  TVector3 origin = aTrack->GetParamFirst().GetOrigin();
155  TVector3 dir = aTrack->GetParamFirst().GetMomentum();
156 
157  //std::cout << "OriginValue: " <<origin.X() << "/" << origin.Y()<< "/" << origin.Z() << std::endl;
158  //std::cout << "DirValue: " <<dir.X() << "/" << dir.Y()<< "/" << dir.Z() << std::endl;
159 
160  Double_t t = (z - origin.Z())/dir.Z();
161 
162  return origin + t * dir;
163 }
164 
165 // -------------------------------------------------------------------------
166 
168 {
169  // fOutputArray->Delete();
170 }
171 
173 {
174  fHc0c0->Write();
175  fHc0c1->Write();
176  fHc0c2->Write();
177  fHc0c3->Write();
178  fHc0c0cut->Write();
179  fHc0c1cut->Write();
180  fHc0c2cut->Write();
181  fHc0c3cut->Write();
182 }
183 
int fVerbose
Definition: poormantracks.C:24
TClonesArray * fTrackArray
Int_t res
Definition: anadigi.C:166
Int_t i
Definition: run_full.C:25
TVector3 GetPosition() const
Definition: PndSdsHit.h:93
virtual void Exec(Option_t *opt)
std::vector< PndTrackCandHit > GetSortedHits()
TVector3 PropagateToZ(PndTrack *aTrack, Double_t z)
virtual void FinishTask()
virtual InitStatus ReInit()
TClonesArray * fHitArray
Double_t
TClonesArray * fProjectedHitArray
Int_t GetNDF() const
Definition: PndTrack.h:35
Double_t z
virtual InitStatus Init()
Double_t GetChi2() const
Definition: PndTrack.h:34
virtual void FinishEvent()
ClassImp(PndAnaContFact)
TClonesArray * fMissingHitArray
TTree * t
Definition: bump_analys.C:13
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
drchit SetVerbose(iVerbose)
Int_t GetSensorID() const
Definition: PndSdsHit.h:90
PndTrackCand * GetTrackCandPtr()
Definition: PndTrack.h:48
TClonesArray * fGoodHitArray
FairTrackParP GetParamFirst()
Definition: PndTrack.h:49