77 ********************************************************************************/
88#include " FairTutorialDet4StraightLineFitter.h"
99
10- #include " FairLogger.h" // for FairLogger, etc
1110#include " FairRootManager.h" // for FairRootManager
1211#include " FairTrackParam.h" // for FairTrackParam
1312#include " FairTutorialDet4Hit.h" // for FairTutorialDet4Hit
1413
15- #include < TClonesArray.h> // for TClonesArray
1614#include < TF1.h> // for TF1
1715#include < TGraphErrors.h> // for TGraphErrors
1816#include < TVector3.h> // for TVector3
19- #include < set> // for set, set<>::iterator, etc
17+ #include < fairlogger/Logger.h>
18+ #include < set>
2019
2120FairTutorialDet4StraightLineFitter::FairTutorialDet4StraightLineFitter ()
2221 : FairTask(" FairTutorialDet4StraightLineFitter" )
23- , fHits(nullptr )
24- , fTracks(nullptr )
22+ , fTracks(FairTrackParam::Class(), 100)
2523 , fVersion(2 )
2624{
2725 LOG (debug) << " Default Constructor of FairTutorialDet4StraightLineFitter" ;
2826}
2927
30- FairTutorialDet4StraightLineFitter::~FairTutorialDet4StraightLineFitter ()
31- {
32- LOG (debug) << " Destructor of FairTutorialDet4StraightLineFitter" ;
33- if (fTracks ) {
34- fTracks ->Delete ();
35- delete fTracks ;
36- }
37- }
38-
3928InitStatus FairTutorialDet4StraightLineFitter::Init ()
4029{
4130 LOG (debug) << " Initilization of FairTutorialDet4StraightLineFitter" ;
@@ -45,7 +34,7 @@ InitStatus FairTutorialDet4StraightLineFitter::Init()
4534
4635 // Get a pointer to the previous already existing data level
4736
48- fHits = static_cast <TClonesArray*>(ioman->GetObject (" TutorialDetHit" ));
37+ fHits = dynamic_cast <TClonesArray const *>(ioman->GetObject (" TutorialDetHit" ));
4938 if (!fHits ) {
5039 LOG (error) << " No InputDataLevelName array!\n "
5140 << " FairTutorialDet4StraightLineFitter will be inactive" ;
@@ -54,8 +43,7 @@ InitStatus FairTutorialDet4StraightLineFitter::Init()
5443
5544 // Create the TClonesArray for the output data and register
5645 // it in the IO manager
57- fTracks = new TClonesArray (" FairTrackParam" , 100 );
58- ioman->Register (" TutorialDetTrack" , " TutorialDet" , fTracks , kTRUE );
46+ ioman->Register (" TutorialDetTrack" , " TutorialDet" , &fTracks , kTRUE );
5947
6048 // Do whatever else is needed at the initilization stage
6149 // Create histograms to be filled
@@ -64,12 +52,6 @@ InitStatus FairTutorialDet4StraightLineFitter::Init()
6452 return kSUCCESS ;
6553}
6654
67- InitStatus FairTutorialDet4StraightLineFitter::ReInit ()
68- {
69- LOG (debug) << " Initilization of FairTutorialDet4StraightLineFitter" ;
70- return kSUCCESS ;
71- }
72-
7355void FairTutorialDet4StraightLineFitter::Exec (Option_t* /* option*/ )
7456{
7557 LOG (debug) << " Exec of FairTutorialDet4StraightLineFitter" ;
@@ -79,7 +61,6 @@ void FairTutorialDet4StraightLineFitter::Exec(Option_t* /*option*/)
7961 }
8062
8163 // Declare some variables
82- FairTutorialDet4Hit* hit = nullptr ;
8364 /*
8465 Int_t detID = 0; // Detector ID
8566 Int_t trackID = 0; // Track index
@@ -98,7 +79,7 @@ void FairTutorialDet4StraightLineFitter::Exec(Option_t* /*option*/)
9879 Float_t* YPosErr = new Float_t[nHits];
9980
10081 for (Int_t iHit = 0 ; iHit < nHits; iHit++) {
101- hit = static_cast <FairTutorialDet4Hit*>(fHits ->At (iHit));
82+ auto hit = static_cast <FairTutorialDet4Hit const *>(fHits ->At (iHit));
10283 if (!hit) {
10384 continue ;
10485 }
@@ -111,24 +92,22 @@ void FairTutorialDet4StraightLineFitter::Exec(Option_t* /*option*/)
11192 YPosErr[iHit] = hit->GetDy ();
11293 }
11394
114- TF1* f1 = new TF1 (" f1" , " [0]*x + [1]" );
115- TGraphErrors* LineGraph;
116-
117- LineGraph = new TGraphErrors (nHits, ZPos, XPos, 0 , XPosErr);
118- LineGraph->Fit (" f1" , " Q" );
119- Double_t SlopeX = f1->GetParameter (0 );
120- Double_t OffX = f1->GetParameter (1 );
121- Double_t Chi2X = f1->GetChisquare ();
95+ auto f1 = TF1 (" f1" , " [0]*x + [1]" );
96+ auto linegraphX = TGraphErrors (nHits, ZPos, XPos, nullptr , XPosErr);
97+ linegraphX.Fit (&f1, " Q" );
98+ Double_t SlopeX = f1.GetParameter (0 );
99+ Double_t OffX = f1.GetParameter (1 );
100+ Double_t Chi2X = f1.GetChisquare ();
122101 Double_t SlopeY = 0 .;
123102 Double_t OffY = 0 .;
124103 Double_t Chi2Y;
125104
126105 if (2 == fVersion ) {
127- LineGraph = new TGraphErrors (nHits, ZPos, YPos, 0 , YPosErr);
128- LineGraph-> Fit (" f1 " , " Q" );
129- SlopeY = f1-> GetParameter (0 );
130- OffY = f1-> GetParameter (1 );
131- Chi2Y = f1-> GetChisquare ();
106+ auto linegraphY = TGraphErrors (nHits, ZPos, YPos, nullptr , YPosErr);
107+ linegraphY. Fit (&f1 , " Q" );
108+ SlopeY = f1. GetParameter (0 );
109+ OffY = f1. GetParameter (1 );
110+ Chi2Y = f1. GetChisquare ();
132111
133112 LOG (debug) << XPos[0 ] << " ," << XPos[nHits - 1 ] << " ," << YPos[0 ] << " ," << YPos[nHits - 1 ] << " ," << ZPos[0 ]
134113 << " ," << ZPos[nHits - 1 ];
@@ -141,15 +120,14 @@ void FairTutorialDet4StraightLineFitter::Exec(Option_t* /*option*/)
141120 LOG (debug) << " Chi2(x,y): " << Chi2X << " ," << Chi2Y;
142121 }
143122
144- FairTrackParam* track = new FairTrackParam ( );
123+ auto track = static_cast < FairTrackParam*>( fTracks . ConstructedAt ( 0 ) );
145124 track->SetX (OffX);
146125 track->SetTx (SlopeX);
147126 track->SetZ (0 .);
148127 if (2 == fVersion ) {
149128 track->SetY (OffY);
150129 track->SetTy (SlopeY);
151130 }
152- new ((*fTracks )[0 ]) FairTrackParam (*track);
153131 // const TMatrixFSym matrix;
154132 // Double_t Z = 0.;
155133 // new ((*fTracks)[0]) FairTrackParam(OffX, OffY, Z, SlopeX, SlopeY, matrix);
@@ -168,15 +146,13 @@ Bool_t FairTutorialDet4StraightLineFitter::IsGoodEvent()
168146 // event, so we have to check for this.
169147 // In the end the algorithm should be able to work also with
170148 // missing hits in some stations
171- FairTutorialDet4Hit* hit;
172149 std::set<Int_t> detIdSet;
173- std::set<Int_t>::iterator it;
174150
175151 Int_t nHits = fHits ->GetEntriesFast ();
176152 for (Int_t iHit = 0 ; iHit < nHits; ++iHit) {
177- hit = static_cast <FairTutorialDet4Hit*>(fHits ->At (iHit));
153+ auto hit = static_cast <FairTutorialDet4Hit const *>(fHits ->At (iHit));
178154 Int_t detId = hit->GetDetectorID ();
179- it = detIdSet.find (detId);
155+ auto it = detIdSet.find (detId);
180156 if (it == detIdSet.end ()) {
181157 detIdSet.insert (detId);
182158 } else {
@@ -187,8 +163,3 @@ Bool_t FairTutorialDet4StraightLineFitter::IsGoodEvent()
187163 }
188164 return kTRUE ;
189165}
190-
191- void FairTutorialDet4StraightLineFitter::Finish ()
192- {
193- LOG (debug) << " Finish of FairTutorialDet4StraightLineFitter" ;
194- }
0 commit comments