15 #include <TClonesArray.h>
17 #include <TGraphErrors.h>
22 :
FairTask(
"FairTutorialDet4StraightLineFitter")
27 LOG(debug) <<
"Default Constructor of FairTutorialDet4StraightLineFitter";
32 LOG(debug) <<
"Destructor of FairTutorialDet4StraightLineFitter";
41 LOG(debug) <<
"SetParContainers of FairTutorialDet4StraightLineFitter";
54 LOG(debug) <<
"Initilization of FairTutorialDet4StraightLineFitter";
61 fHits =
static_cast<TClonesArray*
>(ioman->
GetObject(
"TutorialDetHit"));
63 LOG(error) <<
"No InputDataLevelName array!\n"
64 <<
"FairTutorialDet4StraightLineFitter will be inactive";
70 fTracks =
new TClonesArray(
"FairTrackParam", 100);
71 ioman->
Register(
"TutorialDetTrack",
"TutorialDet", fTracks, kTRUE);
82 LOG(debug) <<
"Initilization of FairTutorialDet4StraightLineFitter";
88 LOG(debug) <<
"Exec of FairTutorialDet4StraightLineFitter";
106 Int_t nHits = fHits->GetEntriesFast();
107 Float_t* ZPos =
new Float_t[nHits];
108 Float_t* XPos =
new Float_t[nHits];
109 Float_t* XPosErr =
new Float_t[nHits];
110 Float_t* YPos =
new Float_t[nHits];
111 Float_t* YPosErr =
new Float_t[nHits];
113 for (Int_t iHit = 0; iHit < nHits; iHit++) {
119 XPos[iHit] = hit->
GetX();
120 YPos[iHit] = hit->
GetY();
121 ZPos[iHit] = hit->
GetZ();
123 XPosErr[iHit] = hit->
GetDx();
124 YPosErr[iHit] = hit->
GetDy();
127 TF1* f1 =
new TF1(
"f1",
"[0]*x + [1]");
128 TGraphErrors* LineGraph;
130 LineGraph =
new TGraphErrors(nHits, ZPos, XPos, 0, XPosErr);
131 LineGraph->Fit(
"f1",
"Q");
132 Double_t SlopeX = f1->GetParameter(0);
133 Double_t OffX = f1->GetParameter(1);
134 Double_t Chi2X = f1->GetChisquare();
135 Double_t SlopeY = 0.;
140 LineGraph =
new TGraphErrors(nHits, ZPos, YPos, 0, YPosErr);
141 LineGraph->Fit(
"f1",
"Q");
142 SlopeY = f1->GetParameter(0);
143 OffY = f1->GetParameter(1);
144 Chi2Y = f1->GetChisquare();
146 LOG(debug) << XPos[0] <<
"," << XPos[nHits - 1] <<
"," << YPos[0] <<
"," << YPos[nHits - 1] <<
"," << ZPos[0]
147 <<
"," << ZPos[nHits - 1];
148 Double_t XSlope = (XPos[nHits - 1] - XPos[0]) / (ZPos[nHits - 1] - ZPos[0]);
149 Double_t YSlope = (YPos[nHits - 1] - YPos[0]) / (ZPos[nHits - 1] - ZPos[0]);
151 LOG(debug) <<
"Slope(x,y): " << SlopeX <<
" ," << SlopeY;
152 LOG(debug) <<
"Slope1(x,y): " << XSlope <<
" ," << YSlope;
153 LOG(debug) <<
"Offset(x,y): " << OffX <<
" ," << OffY;
154 LOG(debug) <<
"Chi2(x,y): " << Chi2X <<
" ," << Chi2Y;
159 track->
SetTx(SlopeX);
163 track->
SetTy(SlopeY);
177 Bool_t FairTutorialDet4StraightLineFitter::IsGoodEvent()
185 std::set<Int_t> detIdSet;
186 std::set<Int_t>::iterator it;
188 Int_t nHits = fHits->GetEntriesFast();
189 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
192 it = detIdSet.find(detId);
193 if (it == detIdSet.end()) {
194 detIdSet.insert(detId);
virtual void SetParContainers()
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
TObject * GetObject(const char *BrName)
virtual InitStatus ReInit()
Int_t GetDetectorID() const
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
~FairTutorialDet4StraightLineFitter()
FairTutorialDet4StraightLineFitter()