StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFwdQAMaker.cxx
1 #include "StFwdTrackMaker/StFwdQAMaker.h"
2 #include "StFwdQAMaker.h"
3 #include "St_base/StMessMgr.h"
4 #include "StBFChain/StBFChain.h"
5 #include "StFwdTrackMaker/StFwdTrackMaker.h"
6 
7 #include "StFwdTrackMaker/include/Tracker/FwdTracker.h"
8 #include "StFwdTrackMaker/include/Tracker/ObjExporter.h"
9 // StEvent includes
10 #include "StEvent/StBTofCollection.h"
11 #include "StEvent/StBTofHeader.h"
12 #include "StEvent/StEvent.h"
13 #include "StEvent/StFttCluster.h"
14 #include "StEvent/StFttCollection.h"
15 #include "StEvent/StFcsCluster.h"
16 #include "StEvent/StFcsCollection.h"
17 #include "StFcsDbMaker/StFcsDb.h"
18 #include "StRoot/StEpdUtil/StEpdGeom.h"
19 #include "StEvent/StFwdTrackCollection.h"
20 #include "StEvent/StFwdTrack.h"
21 
22 
23 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
24 #include "StMuDSTMaker/COMMON/StMuDst.h"
25 #include "StMuDSTMaker/COMMON/StMuEvent.h"
26 #include "StMuDSTMaker/COMMON/StMuFstCollection.h"
27 #include "StMuDSTMaker/COMMON/StMuFstHit.h"
28 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
29 #include "StMuDSTMaker/COMMON/StMuFwdTrack.h"
30 #include "StMuDSTMaker/COMMON/StMuFwdTrackCollection.h"
31 #include "StMuDSTMaker/COMMON/StMuFcsCollection.h"
32 #include "StMuDSTMaker/COMMON/StMuFcsCluster.h"
33 #include "StMuDSTMaker/COMMON/StMuFcsHit.h"
34 #include "StMuDSTMaker/COMMON/StMuFttCluster.h"
35 #include "StMuDSTMaker/COMMON/StMuFttPoint.h"
36 #include "StMuDSTMaker/COMMON/StMuMcTrack.h"
37 #include "StMuDSTMaker/COMMON/StMuFstHit.h"
38 
39 // ClassImp(FcsClusterWithStarXYZ);
40 
43  header.clear();
44  mcTracks.reset();
45  fttPoints.reset();
46  fttClusters.reset();
47  fstPoints.reset();
48  reco.reset();
49  seeds.reset();
50  wcal.reset();
51  hcal.reset();
52  wcalHits.reset();
53  hcalHits.reset();
54  epdHits.reset();
55 }
56 
57 FcsClusterWithStarXYZ::FcsClusterWithStarXYZ( StMuFcsCluster *clu, StFcsDb *fcsDb ) {
58  if ( nullptr == clu ) return;
59  StThreeVectorD xyz = fcsDb->getStarXYZfromColumnRow(clu->detectorId(),clu->x(),clu->y());
60  float detOffset = 0.0;
61  if ( clu->detectorId() == kFcsEcalNorthDetId || clu->detectorId() == kFcsEcalSouthDetId ){
62  detOffset = 715.0; // cm from IP
63  } else if ( clu->detectorId() == kFcsHcalNorthDetId || clu->detectorId() == kFcsHcalSouthDetId ){
64  detOffset = 807.0; // cm from IP
65  }
66  mXYZ.SetXYZ( xyz.x(), xyz.y(), xyz.z() + detOffset );
67  mClu = clu;
68 }
69 
70 FcsHitWithStarXYZ::FcsHitWithStarXYZ( StMuFcsHit *hit, StFcsDb *fcsDb ) {
71  if ( nullptr == hit ) return;
72  StThreeVectorD xyz = fcsDb->getStarXYZ(hit->detectorId(),hit->id());
73  float detOffset = 0.0;
74  if ( hit->detectorId() == kFcsEcalNorthDetId || hit->detectorId() == kFcsEcalSouthDetId ){
75  detOffset = 715.0; // cm from IP
76  } else if ( hit->detectorId() == kFcsHcalNorthDetId || hit->detectorId() == kFcsHcalSouthDetId ){
77  detOffset = 807.0; // cm from IP
78  } else if ( hit->detectorId() == kFcsPresNorthDetId || hit->detectorId() == kFcsPresSouthDetId ){
79  StEpdGeom epdgeo;
80  double zepd=375.0;
81  int pp,tt,n;
82  double x[5],y[5];
83  fcsDb->getEPDfromId(hit->detectorId(),hit->id(),pp,tt);
84  epdgeo.GetCorners(100*pp+tt,&n,x,y);
85  double x0 = (x[0] + x[1] + x[2] + x[3]) / 4.0;
86  double y0 = (y[0] + y[1] + y[2] + y[3]) / 4.0;
87  xyz.setX(x0);
88  xyz.setY(y0);
89  xyz.setZ(zepd);
90  }
91  mXYZ.SetXYZ( xyz.x(), xyz.y(), xyz.z() + detOffset );
92  mHit = hit;
93 }
94 
95 StFwdQAMaker::StFwdQAMaker() : StMaker("fwdQAMaker"), mTreeFile(nullptr), mTree(nullptr) {
96 
97 }
98 
99 int StFwdQAMaker::Init() {
100 
101  mTreeFile = new TFile("fwdtree.root", "RECREATE");
102  mTree = new TTree("fwd", "fwd tracking tree");
103 
104  mTree->Branch("header", &mTreeData. header, 3200, 99 );
105  mTreeData.mcTracks.createBranch(mTree, "mcTracks");
106  mTree->Branch("nSeedTracks", &mTreeData.nSeedTracks, "nSeedTracks/I");
107  mTreeData.fstPoints.createBranch(mTree, "fstHits");
108  mTreeData.fttPoints.createBranch(mTree, "fttPoints");
109  mTreeData.fttClusters.createBranch(mTree, "fttClusters");
110  mTreeData.fstPoints.createBranch(mTree, "fstPoints");
111  mTreeData.wcal.createBranch(mTree, "wcalClusters");
112  mTreeData.hcal.createBranch(mTree, "hcalClusters");
113 
114  mTreeData.wcalHits.createBranch(mTree, "wcalHits");
115  mTreeData.hcalHits.createBranch(mTree, "hcalHits");
116  mTreeData.epdHits.createBranch(mTree, "epdHits");
117 
118  mTreeData.reco.createBranch(mTree, "reco");
119  mTreeData.seeds.createBranch(mTree, "seeds");
120  return kStOk;
121 }
123 
124  if ( mTreeFile && mTree ){
125  mTreeFile->cd();
126  mTree->Write();
127  mTreeFile->Write();
128  LOG_DEBUG << "StFwdQA File written" << endm;
129  }
130  return kStOk;
131 }
133  LOG_INFO << "FWD Report:" << endm;
134  StEvent *mStEvent = static_cast<StEvent *>(GetInputDS("StEvent"));
135  if ( mStEvent ){
136  // report number of fwd tracks
137  auto fwdTracks = mStEvent->fwdTrackCollection();
138  LOG_INFO << "Number of FwdTracks (StFwdTrackCollection): " << fwdTracks->tracks().size() << endm;
139  LOG_INFO << "Number of Ftt Points (StEvent)" << mStEvent->fttCollection()->points().size() << endm;
140  }
141  LOG_INFO << "SETUP START" << endm;
142  // setup the datasets / makers
143  mMuDstMaker = (StMuDstMaker *)GetMaker("MuDst");
144  if(mMuDstMaker) {
145  mMuDst = mMuDstMaker->muDst();
146  mMuForwardTrackCollection = mMuDst->muFwdTrackCollection();
147  mMuFcsCollection = mMuDst->muFcsCollection();
148  if (mMuForwardTrackCollection){
149  LOG_DEBUG << "Number of StMuFwdTracks: " << mMuForwardTrackCollection->numberOfFwdTracks() << endm;
150  }
151  } else {
152  LOG_DEBUG << "No StMuDstMaker found: " << mMuDstMaker << endm;
153  }
154  mFcsDb = static_cast<StFcsDb *>(GetDataSet("fcsDb"));
155 
156  mFwdTrackMaker = (StFwdTrackMaker*) GetMaker( "fwdTrack" );
157  if (!mFwdTrackMaker) {
158  LOG_WARN << "No StFwdTrackMaker found, skipping StFwdQAMaker" << endm;
159  // return kStOk;
160  }
161 
162  mTreeData.header.run = mMuDst->event()->runNumber();
163  LOG_DEBUG << "SETUP COMPLETE" << endm;
164 
165  auto muFstCollection = mMuDst->muFstCollection();
166  if ( muFstCollection ){
167  LOG_DEBUG << "MuDst has #fst hits: " << muFstCollection->numberOfHits() << endm;
168  for ( size_t i = 0; i < muFstCollection->numberOfHits(); i++ ){
169  StMuFstHit * h = muFstCollection->getHit(i);
170  mTreeData.fstPoints.add( h );
171  }
172  }
173  FillMcTracks();
174  FillTracks();
175  FillFstPoints();
176  FillFttClusters();
177  FillFcsStMuDst();
178  mTree->Fill();
179  return kStOk;
180 }
181 void StFwdQAMaker::Clear(const Option_t *opts) {
182  mTreeData.clear();
183  return;
184 }
185 
186 void StFwdQAMaker::FillFstPoints(){
187  StMuFstCollection * fst = mMuDst->muFstCollection();
188  if (!fst) {
189  LOG_WARN << "No StMuFstCollection ... bye-bye" << endm;
190  return;
191  }
192 
193  // size_t numFwdHitsPrior = mFwdHitsFst.size();
194  LOG_INFO << "Loading " << fst->numberOfHits() << " StMuFstHits" << endm;
195  // TMatrixDSym hitCov3(3);
196  for ( unsigned int index = 0; index < fst->numberOfHits(); index++){
197  StMuFstHit * muFstHit = fst->getHit( index );
198  mTreeData.fstPoints.add( muFstHit );
199 
200 
201  // float vR = muFstHit->localPosition(0);
202  // float vPhi = muFstHit->localPosition(1);
203  // float vZ = muFstHit->localPosition(2);
204 
205  // const float dz0 = fabs( vZ - mFstZFromGeom[0] );
206  // const float dz1 = fabs( vZ - mFstZFromGeom[1] );
207  // const float dz2 = fabs( vZ - mFstZFromGeom[2] );
208  // static const float fstThickness = 2.0; // thickness in cm between inner and outer on sigle plane
209 
210  // // assign disk according to which z value the hit has, within the z-plane thickness
211  // int d = 0 * ( dz0 < fstThickness ) + 1 * ( dz1 < fstThickness ) + 2 * ( dz2 < fstThickness );
212 
213  // float x0 = vR * cos( vPhi );
214  // float y0 = vR * sin( vPhi );
215  // hitCov3 = makeSiCovMat( TVector3( x0, y0, vZ ), mFwdConfig );
216 
217  // LOG_DEBUG << "FST HIT: d = " << d << ", x=" << x0 << ", y=" << y0 << ", z=" << vZ << endm;
218  // mFstHits.push_back( TVector3( x0, y0, vZ) );
219 
220  // // we use d+4 so that both FTT and FST start at 4
221  // mFwdHitsFst.push_back(FwdHit(count++, x0, y0, vZ, d+4, 0, hitCov3, nullptr));
222  // count++;
223  } // index
224 }
225 
226 void StFwdQAMaker::FillTracks() {
227  mTreeData.nSeedTracks = 0;
228  if ( mMuForwardTrackCollection ){
229  LOG_DEBUG << "Adding " << mMuForwardTrackCollection->numberOfFwdTracks() << " FwdTracks (MuDst)" << endm;
230  for ( size_t iTrack = 0; iTrack < mMuForwardTrackCollection->numberOfFwdTracks(); iTrack++ ){
231  auto muTrack = mMuForwardTrackCollection->getFwdTrack(iTrack);
232  mTreeData.reco.add( muTrack );
233 
234  for (auto fsth : muTrack->mFSTPoints){
235  mTreeData.seeds.add( fsth );
236  mTreeData.nSeedTracks++;
237  }
238  for (auto ftth : muTrack->mFTTPoints){
239  mTreeData.seeds.add( ftth );
240  mTreeData.nSeedTracks++;
241  }
242  if ( iTrack > 5000 ) {
243  LOG_WARN << "Truncating to 5000 tracks" << endm;
244  break;
245  }
246  }
247  }
248  LOG_DEBUG << "TRACKS COMPLETE" << endm;
249 }
250 
251 void StFwdQAMaker::FillFcsStMuDst( ) {
252 
253  if ( !mMuDst ){
254  LOG_DEBUG << "No mMuDst found, skipping StFwdQAMaker::FillFcsStEvent" << endm;
255  return;
256  }
257  StMuFcsCollection* fcs = mMuDst->muFcsCollection();
258  if ( !fcs ){
259  LOG_DEBUG << "No muFcsCollection found, skipping StFwdQAMaker::FillFcsStEvent" << endm;
260  return;
261  }
262 
263  StFcsDb* fcsDb=static_cast<StFcsDb*>(GetDataSet("fcsDb"));
264 
265  // LOAD ECAL / HCAL CLUSTERS
266  LOG_INFO << "MuDst has #fcs clusters: " << fcs->numberOfClusters() << endm;
267  for( size_t i = 0; i < fcs->numberOfClusters(); i++){
268  StMuFcsCluster * clu = fcs->getCluster(i);
269  FcsClusterWithStarXYZ *cluSTAR = new FcsClusterWithStarXYZ(clu, fcsDb);
270  if ( clu->detectorId() == kFcsEcalNorthDetId || clu->detectorId() == kFcsEcalSouthDetId ){
271  LOG_INFO << "Adding WCAL Cluster to FwdTree" << endm;
272  mTreeData.wcal.add( cluSTAR );
273  } else if ( clu->detectorId() == kFcsHcalNorthDetId || clu->detectorId() == kFcsHcalSouthDetId ){
274  LOG_INFO << "Adding HCAL Cluster to FwdTree" << endm;
275  mTreeData.hcal.add( cluSTAR );
276  }
277 
278  delete cluSTAR;
279  }
280 
281  // LOAD ECAL / HCAL CLUSTERS
282  LOG_INFO << "MuDst has #fcs hits: " << fcs->numberOfHits() << endm;
283  for( size_t i = 0; i < fcs->numberOfHits(); i++){
284  StMuFcsHit * hit = fcs->getHit(i);
285  FcsHitWithStarXYZ *hitSTAR = new FcsHitWithStarXYZ(hit, fcsDb);
286  if ( hit->detectorId() == kFcsEcalNorthDetId || hit->detectorId() == kFcsEcalSouthDetId ){
287  LOG_DEBUG << "Adding WCAL Cluster to FwdTree" << endm;
288  mTreeData.wcalHits.add( hitSTAR );
289  } else if ( hit->detectorId() == kFcsHcalNorthDetId || hit->detectorId() == kFcsHcalSouthDetId ){
290  LOG_DEBUG << "Adding HCAL Cluster to FwdTree" << endm;
291  mTreeData.hcalHits.add( hitSTAR );
292  } else if ( hit->detectorId() == kFcsPresNorthDetId || hit->detectorId() == kFcsPresSouthDetId ){
293  LOG_DEBUG << "Adding PRES hit to FwdTree" << endm;
294  mTreeData.epdHits.add( hitSTAR );
295  }
296  delete hitSTAR;
297  }
298 
299  // TODO, cleanup?
300 }
301 
302 void StFwdQAMaker::FillMcTracks(){
303  // Retrieve pointer to MC tracks
304  TClonesArray *mcTracks = mMuDst->mcArray(1);
305  LOG_INFO << "MuDst has #mc tracks: " << mcTracks->GetEntriesFast() << endm;
306  // Loop over MC vertices
307  for (Int_t iVtx=0; iVtx<mcTracks->GetEntriesFast(); iVtx++) {
308  // Retrieve i-th MC vertex from MuDst
309  StMuMcTrack *mcTrack = (StMuMcTrack*)mcTracks->UncheckedAt(iVtx);
310  if ( !mcTrack ) continue;
311 
312  // Add MC track to the tree
313  mTreeData.mcTracks.add( mcTrack );
314  }
315 }
316 
317 
318 void StFwdQAMaker::FillFttClusters(){
319 
320  auto muFttCollection = mMuDst->muFttCollection();
321  if ( muFttCollection ){
322  LOG_DEBUG << "MuDst has #ftt clusters: " << muFttCollection->numberOfClusters() << endm;
323  for ( size_t i = 0; i < muFttCollection->numberOfClusters(); i++ ){
324  StMuFttCluster * c = muFttCollection->getCluster(i);
325  mTreeData.fttClusters.add( c );
326  }
327 
328  for ( size_t i = 0; i < muFttCollection->numberOfPoints(); i++ ){
329  StMuFttPoint * c = muFttCollection->getPoint(i);
330  mTreeData.fttPoints.add( c );
331  }
332  }
333 }
static StMuFcsCollection * muFcsCollection()
returns pointer to current StMuFcsCollection
Definition: StMuDst.h:395
static StMuFttCollection * muFttCollection()
returns pointer to current StMuFttCollection
Definition: StMuDst.h:397
StMuDst * muDst()
Definition: StMuDstMaker.h:425
FwdTreeHeader header
Primary event vertex.
Definition: StFwdQAMaker.h:152
TClonesArrayWriter< StMuMcTrack > mcTracks
MC tracks.
Definition: StFwdQAMaker.h:154
StThreeVectorD getStarXYZfromColumnRow(int det, float col, float row, float FcsZ=-1.0) const
get the STAR frame cooridnates from other way
Definition: StFcsDb.cxx:863
static StMuFwdTrackCollection * muFwdTrackCollection()
returns pointer to current StMuFwdTrackCollection
Definition: StMuDst.h:401
StThreeVectorD getStarXYZ(int det, float FcsX, float FcsY, float FcsZ=-1.0, float zVertex=0.0) const
get the STAR frame cooridnates from local XYZ [cm]
Definition: StFcsDb.cxx:868
void getEPDfromId(int det, int id, int &pp, int &tt)
Get FCS&#39;s EPD map foom EPD mapping.
Definition: StFcsDb.cxx:1484
static StMuFstCollection * muFstCollection()
returns pointer to current StMuFstCollection
Definition: StMuDst.h:399
Store Cluster with STAR XYZ position.
Definition: StFwdQAMaker.h:117
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Store Hit with STAR XYZ position.
Definition: StFwdQAMaker.h:133
Definition: Stypes.h:41