StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtGeneralBase.cxx
1 #include "StFgtGeneralBase.h"
2 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
3 #include "StRoot/StEvent/StEvent.h"
4 #include "StRoot/StEvent/StFgtCollection.h"
5 
6 #include "StRoot/StEvent/StFgtHitCollection.h"
7 #include "StRoot/StEvent/StFgtHit.h"
8 #include "StRoot/StEvent/StFgtStrip.h"
9 
10 #include "StRoot/StMuDSTMaker/COMMON/StMuDst.h"
11 #include "StRoot/StMuDSTMaker/COMMON/StMuFgtStrip.h"
12 #include "StRoot/StMuDSTMaker/COMMON/StMuFgtAdc.h"
13 #include "StRoot/StMuDSTMaker/COMMON/StMuFgtCluster.h"
14 #include "StRoot/StMuDSTMaker/COMMON/StMuFgtStripAssociation.h"
15 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
16 #include "StMuDSTMaker/COMMON/StMuDst.h"
17 #include "StMuDSTMaker/COMMON/StMuEvent.h"
18 #include "StarClassLibrary/StThreeVectorF.hh"
19 
20 #include <set>
21 //#define COSMIC
22 //#define ONE_HIT_PER_QUAD
23 //#define USE_VTX
24 
25 #ifdef COSMIC
26 //#include "StFgtCosmicAlignment.h"
27 #endif
28 
29 
30 StFgtGeneralBase::StFgtGeneralBase(const Char_t* name): StMaker( name ),m_fillFromEvent(false),evtNr(0),m_effDisk(2), fgtCollection(0), mVertexNumber(0),mUseEHTTrigs(false)
31 {
32  sprintf(fileBase,"%s",".");
33  m_isCosmic=false;
34  chargeMatchCut=1.5;
35  pClusters=new vector<generalCluster>*[6];
36  pClusters[0]=&clustersD1;
37  pClusters[1]=&clustersD2;
38  pClusters[2]=&clustersD3;
39  pClusters[3]=&clustersD4;
40  pClusters[4]=&clustersD5;
41  pClusters[5]=&clustersD6;
42 
43  pStrips=new vector<generalStrip>[50]; //for each quad so we don't have to lookup so much...
44  StFgtDbMaker *fgtDbMkr = static_cast< StFgtDbMaker* >( GetMakerInheritsFrom( "StFgtDbMaker" ) );
45  if( !fgtDbMkr ){
46  LOG_FATAL << "StFgtDb not provided and error finding StFgtDbMaker" << endm;
47  }
48  mDb = fgtDbMkr->getDbTables();
49  if( !mDb ){
50  LOG_FATAL << "StFgtDb not provided and error retrieving pointer from StFgtDbMaker '"
51  << fgtDbMkr->GetName() << endm;
52  }
53  chargeMaxAdcCorr=new TH2D("chargeMaxAdcCorr","chargeMaxAdcCorr",50,0,10000,50,0,1000);
54  chargeMaxAdcIntCorr=new TH2D("chargeMaxIntAdcCorr","chargeMaxAdcIntCorr",50,0,10000,50,0,1000);
55  hIpZEv=new TH1D("IP_ZEv","IP_ZEv",70,-150,150);
56  clusWChargeMatch=new TH1D("clusWChargeMatch","clusWChargeMatch",101,0,100);
57  clusWOChargeMatch=new TH1D("clusWOChargeMatch","clusWOChargeMatch",101,0,100);
58  char buffer[100];
59  hNumPulsesP=new TH1D*[6*4];
60  hNumChargesP=new TH1D*[6*4];
61  hNumPulsesR=new TH1D*[6*4];
62  hNumChargesR=new TH1D*[6*4];
63  hNumClustersP=new TH1D*[6*4];
64  hNumClustersR=new TH1D*[6*4];
65 
66 
67  for(int iD=0;iD<6;iD++)
68  {
69  for(int iQ=0;iQ<4;iQ++)
70  {
71  sprintf(buffer,"validPulsesP_D%d_Q%d",iD+1,iQ);
72  hNumPulsesP[iD*4+iQ]=new TH1D(buffer,buffer,100,0,100);
73  sprintf(buffer,"validPulsesR_D%d_Q%d",iD+1,iQ);
74  hNumPulsesR[iD*4+iQ]=new TH1D(buffer,buffer,100,0,100);
75  sprintf(buffer,"validChargesR_D%d_Q%d",iD+1,iQ);
76  hNumChargesR[iD*4+iQ]=new TH1D(buffer,buffer,200,0,200);
77  sprintf(buffer,"validChargesP_D%d_Q%d",iD+1,iQ);
78  hNumChargesP[iD*4+iQ]=new TH1D(buffer,buffer,200,0,200);
79  sprintf(buffer,"validClustersP_D%d_Q%d",iD+1,iQ);
80  hNumClustersP[iD*4+iQ]=new TH1D(buffer,buffer,200,0,200);
81  sprintf(buffer,"validClustersR_D%d_Q%d",iD+1,iQ);
82  hNumClustersR[iD*4+iQ]=new TH1D(buffer,buffer,200,0,200);
83  }
84  }
85 
86 
87 }
88 
89 void StFgtGeneralBase::SetFileBase(const Char_t* m_filebase)
90 {
91  cout <<"setting file base to " << m_filebase <<endl;
92  sprintf(fileBase,"%s",m_filebase);
93 }
94 
95 
97 {
98  cout <<"gb finish" <<endl;
99  evStatistics=new TH1D("fgtEventStatistics","fgtEventStatistics",10,0,9);
100  // TCanvas c;
101  // chargeMaxAdcCorr->Draw("colz");
103  // chargeMaxAdcIntCorr->Draw("colz");
105  // hIpZEv->Draw();
107  // cout <<"done saving" <<endl;
108  char buffer[100];
109  sprintf(buffer,"%s/general.root",fileBase);
110  TFile f(buffer,"recreate");
111  clusWChargeMatch->Write();
112  clusWOChargeMatch->Write();
113  for(int iD=0;iD<6;iD++)
114  {
115  for(int iQ=0;iQ<4;iQ++)
116  {
117  hNumPulsesP[iD*4+iQ]->Write();
118  hNumChargesP[iD*4+iQ]->Write();
119  hNumClustersP[iD*4+iQ]->Write();
120  hNumPulsesR[iD*4+iQ]->Write();
121  hNumChargesR[iD*4+iQ]->Write();
122  hNumClustersR[iD*4+iQ]->Write();
123  }
124  }
125  f.Write();
126  f.Close();
127  cout <<"done" <<endl;
128  return kStOk;
129 }
130 
131 Bool_t StFgtGeneralBase::validPulse(generalStrip& strip)
132 {
133  for(int i=0;i<4;i++)
134  {
135 
136  Float_t adc1=strip.adc[i];
137  Float_t adc2=strip.adc[i+1];
138  Float_t adc3=strip.adc[i+2];
139  Float_t cut=5*strip.pedErr;
140  if(adc1>cut && adc2 >cut && adc3 > cut)
141  {
142  if(adc1 <adc2 && adc2 < adc3)
143  return true;
144  }
145  }
146  return false;
147 }
148 
149 
151 {
152  if(!m_fillFromEvent)
153  {
154 
155  //if we constructed fgtCollection ourself, delete it ourself
156  if(fgtCollection)
157  {
158  //fgtCollection->Clear();
159  //delete fgtCollection;
160  }
161  }
162 
163  Int_t ierr=kStOk;
164  evtNr++;
165  clustersD1.clear();
166  clustersD2.clear();
167  clustersD3.clear();
168  clustersD4.clear();
169  clustersD5.clear();
170  clustersD6.clear();
171  // cout << " clearing strips..." <<endl;
172  for(int i=0;i<50;i++)
173  {
174  pStrips[i].clear();
175  }
176  // cout << " done" <<endl;
177  if(m_fillFromEvent)
178  {
179  StEvent* eventPtr = (StEvent*)GetInputDS("StEvent");
180  fgtCollection=eventPtr->fgtCollection();
181  if( eventPtr ) {
182  fillFromStEvent(fgtCollection);
183  }
184  }
185  else
186  {
187  fgtCollection=new StFgtCollection();
188  fillFromMuDst(*fgtCollection);
189  AddData(new TObjectSet("FGTCOLLECTION",fgtCollection,kTRUE));
190  // cout <<"read mDst " <<endl;
191  fillFromStEvent(fgtCollection);
192  // cout <<"filled event" <<endl;
193  }
194 
195  //do associations
196  doEvAssoc();
197  mapGeoId2Cluster.clear();
198  return ierr;
199 }
200 
201 
202 void StFgtGeneralBase::doEvAssoc()
203 {
204  for(int i=0;i<6;i++)
205  {
206  for(vector<generalCluster>::iterator it=pClusters[i]->begin();it!=pClusters[i]->end();it++)
207  {
208  Int_t geoId=it->centralStripGeoId;
209  StFgtHitCollection *fgtHitColPtr = 0;
210  fgtHitColPtr = fgtCollection->getHitCollection( i );
211  if( fgtHitColPtr )
212  {
213  const StSPtrVecFgtHit& hitVec = fgtHitColPtr->getHitVec();
214  StSPtrVecFgtHitConstIterator hitIter;
215  for( hitIter = hitVec.begin(); hitIter != hitVec.end(); ++hitIter )
216  {
217  Int_t geoId2=(*hitIter)->getCentralStripGeoId();
218  if(geoId==geoId2)//found match
219  {
220  it->fgtHit=(*hitIter);
221  }
222  }
223  }
224 
225  }
226  }
227 }
228 Int_t StFgtGeneralBase::fillFromStEvent(StFgtCollection* fgtCollectionPtr)
229 {
230  Int_t ierr = kStFatal;
231 
232  StFgtHitCollection *fgtHitColPtr = 0;
233  if( fgtCollectionPtr ){
234  // got this far, so flag that this is the right input.
235  ierr = kStOk;
236  // loop over discs
237  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc ){
238  fgtHitColPtr = fgtCollectionPtr->getHitCollection( disc );
239  if( fgtHitColPtr ){
240  const StSPtrVecFgtHit& hitVec = fgtHitColPtr->getHitVec();
241  StSPtrVecFgtHitConstIterator hitIter;
242  set<int> quadsHit;
243 
244  for( hitIter = hitVec.begin(); hitIter != hitVec.end(); ++hitIter)
245  {
246  Short_t quad, discK, strip;
247  Char_t layer;
248 
249  Double_t posR=(*hitIter)->getPositionR();
250  Double_t posPhi=(*hitIter)->getPositionPhi();
251 
252  Double_t discZ=getLocDiscZ(disc);
253  float tmpX, tmpY,tmpZ,tmpP,tmpR;
254  tmpR=posR;
255  tmpP=posPhi;
256  tmpZ=discZ;
257 #ifdef COSMIC
258  // getAlign(disc,posPhi,posR,tmpX,tmpY,tmpZ,tmpP,tmpR);
260 #endif
261  posR=tmpR;
262  posPhi=tmpP;
263  discZ=tmpZ;
264 
265  Int_t geoId=(*hitIter)->getCentralStripGeoId();
266  // cout <<"central geoId in cluster:" << geoId <<endl;
267 
268  StFgtGeom::decodeGeoId((*hitIter)->getCentralStripGeoId(),discK, quad, layer, strip);
269  if(quad<0 && discK<0)//Ithink these are the error conditions
270  {
271  if(discK!=disc)
272  cout <<" disc - geo id mismatch...disk: " <<disc <<" or " << discK <<" geo id is " << (*hitIter)->getCentralStripGeoId()<<endl;
273  cout <<"bad read1" <<endl;
274  continue;
275  }
276 #ifdef ONE_HIT_PER_QUAD
277  if(quadsHit.find(quad)!=quadsHit.end())
278  {
279  continue;
280  }
281  quadsHit.insert(quad);
282 #endif
283  // Int_t clusterSizePhi=(*hitIter)->getStripWeightMap().size();
284  Int_t clusterSize=(*hitIter)->getStripWeightMap().size();
285  Double_t clusterCharge=(*hitIter)->charge();
286  Double_t clusterUncert=(*hitIter)->getChargeUncert();
287  // cout <<" r pos : " << posR << " phi: " << posPhi << " charge: " << clusterCharge << " unert: " << clusterUncert <<endl;
288  //sometimes (rarely two clusters have the same geo id (some split I guess), don't insert twice, that messes the indexing up
289  if(mapGeoId2Cluster.find(geoId)==mapGeoId2Cluster.end())
290  {
291  pClusters[disc]->push_back(generalCluster(geoId,layer,discZ,posPhi,posR,quad,disc,strip, clusterSize, clusterCharge,clusterUncert));
292  // cout <<"inserting geo id " << geoId <<" into map at pos: " << ((pClusters[disc]->size()-1)) <<" disc " << disc <<endl;
293  mapGeoId2Cluster[geoId]=((pClusters[disc]->size()-1));
294  }
295  else
296  {
297  // cout <<"geoId " << geoId << " already exists " <<endl;
298  }
299  }
300  };
301  }
303  for( Int_t disc = 0; disc < kFgtNumDiscs; disc++ )
304  {
305  StFgtStripCollection *stripCollectionPtr = fgtCollectionPtr->getStripCollection( disc);
306  if( stripCollectionPtr)
307  {
308  StSPtrVecFgtStrip& stripVec = stripCollectionPtr->getStripVec();
309  StSPtrVecFgtStripIterator stripIter;
310  // cout <<"we have " << stripVec.size() << " strips in disc: " << disc <<endl;
311  for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
312  StFgtStrip *strip = *stripIter;
313  // Float_t ped = 0, pedErr = 0;
314  if( strip ){
315  Int_t geoId=strip->getGeoId();
316  // cout <<"looking at strip geo id: "<< strip->getGeoId()<<endl;
317  Int_t cSeedType=strip->getClusterSeedType();
318  // if(cSeedType==kFgtClusterSeedInSeaOfNoise)
319  // cout <<"noisy strip " << geoId <<endl;
320  Double_t charge=strip->getCharge();
321  Double_t chargeUncert=strip->getChargeUncert();
322  Short_t quad, discK, stripI;
323  Char_t layer;
324  StFgtGeom::decodeGeoId(geoId,discK, quad, layer, stripI);
325  // cout <<"quad: " << quad <<endl;
326  if(discK<0 || discK>6 || quad <0 || quad > 4 || (layer!='P' && layer !='R'))
327  {
328  // cout <<"bad read2" <<endl;
329  continue;
330  }
331  Double_t ped=0.0; //get from DB
332  Double_t pedErr=0.0;
333  Int_t rdo, arm, apv, chan;
334  mDb->getElecCoordFromGeoId(geoId, rdo,arm,apv,chan);
335  Int_t elecId = StFgtGeom::encodeElectronicId( rdo, arm, apv, chan );
336  ped = mDb->getPedestalFromElecId( elecId );
337  pedErr = mDb->getPedestalSigmaFromElecId( elecId );
338  if(quad<4)
339  {
340 
341  if(quad<0)
342  {
343  cout <<"bad read3"<<endl;
344  }
345  // cout <<"looking at disc: " << disc << " quad: " << quad <<" index: " << disc*4+quad <<endl;
346  // cout <<"pushing back to disc: "<< disc <<" quad: " << quad <<endl;
347  pStrips[disc*4+quad].push_back(generalStrip(geoId,ped,pedErr,cSeedType,charge, chargeUncert));
348  Double_t maxAdc=-9999;
349  for(int j=0;j<7;j++)
350  {
351  pStrips[disc*4+quad].back().adc[j]=strip->getAdc(j);
352  if(strip->getAdc(j)>maxAdc)
353  maxAdc=strip->getAdc(j);
354  }
355  pStrips[disc*4+quad].back().maxAdc=maxAdc;
356  if(mapGeoId2Cluster.find(geoId)!=mapGeoId2Cluster.end())
357  {
358  // cout <<"this strip geo ID ("<<geoId<<") supposedly belongs to cluster with geo " << (*pClusters[disc])[mapGeoId2Cluster[geoId] ].centralStripGeoId <<" int index: " << mapGeoId2Cluster[geoId] <<endl;
359  // cout <<" strip disc: " << disc <<" cluster disc: " << (*pClusters[disc])[mapGeoId2Cluster[geoId] ].disc << " index: " << (pStrips[disc*4+quad].size()-1) << " quad: " << quad <<endl;
360  if(mapGeoId2Cluster[geoId]>=(*pClusters[disc]).size())
361  {
362  // cout <<" bad read5" <<endl;
363  // cout <<"geo id: " << geoId << " map: " << mapGeoId2Cluster[geoId] <<" size:" << (*pClusters[disc]).size() <<" disc: " << disc <<endl;
364  }
365  (*pClusters[disc])[mapGeoId2Cluster[geoId] ].centerStripIdx=(pStrips[disc*4+quad].size()-1);
366  (*pClusters[disc])[mapGeoId2Cluster[geoId] ].maxAdc=maxAdc;
367  }
368  }
369 
370  }
371  }
372  }
373  }
374 
375 
377 
378 
379 
380  for(int iDx=0;iDx<6;iDx++)
381  {
382  int dCounter=0;
383  vector<generalCluster>::iterator it=pClusters[iDx]->begin();
384  for(;it!=pClusters[iDx]->end();it++)
385  {
386  dCounter++;
387  // it->hasMatch=true;
388  Int_t centerStripId=it->centerStripIdx;
389  if(centerStripId<0)
390  {
391  //don't worry, probably a cluster at low r where the center strip is missing
392  // cout <<"bad read4 for cluster with geoid: "<< it->centralStripGeoId <<" index: " << it->centerStripIdx <<" quad: " << it->quad << "index: " <<dCounter-1<< " disc: " << iDx <<" phi " << it->posPhi <<" r: " << it->posR <<endl;
393  continue;
394  }
395 
396  Double_t maxChargeInt=it->maxAdc;
397  // cout <<"center strip" << centerStripId<<" idx: " << iDx << " quad: " << it->quad <<endl;
398  // cout <<" size:" <<pStrips[iDx*4+it->quad].size()<<endl;
399  if(centerStripId>=pStrips[iDx*4+it->quad].size())
400  {
401  cout <<"bad read5" <<endl;
402  continue;
403  }
404  Int_t oldGeoId=(pStrips[iDx*4+it->quad])[centerStripId].geoId;
405  Int_t m_seedType=(pStrips[iDx*4+it->quad])[centerStripId].seedType;
406  Int_t stripCounter=(centerStripId-1);
407  while(stripCounter>=0)
408  {
409  // cout <<"stripcounter"<< stripCounter <<endl;
410  Int_t seedType=(pStrips[iDx*4+it->quad])[stripCounter].seedType;
411  if((seedType==kFgtSeedType1)||(seedType==kFgtSeedType2)||(seedType==kFgtSeedType3))
412  {
413  m_seedType=seedType;
414  }
415  if(!((seedType==kFgtClusterPart)||(seedType==kFgtClusterEndUp)||(seedType==kFgtClusterEndDown)||(seedType==kFgtSeedType1)||(seedType==kFgtSeedType2)||(seedType==kFgtSeedType3)))
416  break;
417  if(fabs(oldGeoId-(pStrips[iDx*4+it->quad])[stripCounter].geoId)>1)
418  break;
419  maxChargeInt+=(pStrips[iDx*4+it->quad])[stripCounter].maxAdc;
420  oldGeoId=(pStrips[iDx*4+it->quad])[stripCounter].geoId;
421  stripCounter--;
422  }
423  //and go up
424  stripCounter=(centerStripId+1);
425  //should be strictly smaller
426  while(stripCounter<(pStrips[iDx*4+it->quad]).size())
427  {
428  Int_t seedType=(pStrips[iDx*4+it->quad])[stripCounter].seedType;
429  if(!((seedType==kFgtClusterPart)||(seedType==kFgtClusterEndUp)||(seedType==kFgtClusterEndDown)||(seedType==kFgtSeedType1)||(seedType==kFgtSeedType2)||(seedType==kFgtSeedType3)))
430  break;
431  if(fabs(oldGeoId-(pStrips[iDx*4+it->quad])[stripCounter].geoId)>1)
432  break;
433  maxChargeInt+=(pStrips[iDx*4+it->quad])[stripCounter].maxAdc;
434  oldGeoId=(pStrips[iDx*4+it->quad])[stripCounter].geoId;
435  stripCounter++;
436  if((seedType==kFgtSeedType1)||(seedType==kFgtSeedType2)||(seedType==kFgtSeedType3))
437  {
438  m_seedType=seedType;
439  }
440  }
441  it->maxAdcInt=maxChargeInt;
442  it->seedType=m_seedType;
443  chargeMaxAdcCorr->Fill(it->clusterCharge,it->maxAdc);
444  chargeMaxAdcIntCorr->Fill(it->clusterCharge,maxChargeInt);
445  }
446  }
448 
449 
450 
451  // cout <<"filled from event " <<endl;
452  checkMatches();
453  checkNumPulses();
454  return ierr;
455 
456  }
457 }
458 
460 {
461  Int_t ierr = kStOk;
462  StFgtStripCollection* stripCollectionPtr[kFgtNumDiscs];
463  StFgtHitCollection* hitCollectionPtr[kFgtNumDiscs];
464  for(int discIdx=0;discIdx<kFgtNumDiscs;discIdx++)
465  {
466  stripCollectionPtr[discIdx] = fgtCollection.getStripCollection( discIdx );
467  hitCollectionPtr[discIdx] = fgtCollection.getHitCollection( discIdx );
468  }
469  // get pointer to input
470  const StMuDst* muDst = (const StMuDst*)GetInputDS("MuDst");
471  //temp trigger ids for ehts like stuff
472 
473 
474 
475  if( muDst )
476  {
477  StMuEvent *event = static_cast<StMuEvent*>(muDst->event());
478  if( event ){
479  StMuTriggerIdCollection trig=event->triggerIdCollection();
480  StTriggerId l1trig=trig.nominal();
481  Bool_t haveEHTTrig=false;
482  for(int iTrig=0;iTrig<3;iTrig++)
483  {
484 
485  if(l1trig.isTrigger(trigID[iTrig]))
486  {
487  cout <<"found " <<endl;
488  haveEHTTrig=true;
489  }
490  }
491  const StThreeVectorF& v = event->primaryVertexPosition();
492  StEventInfo &info=event->eventInfo();
493  int nPrimV=muDst->numberOfPrimaryVertices();
494  // cout <<"nPrimV: " << nPrimV <<" vertex num: " << mVertexNumber << " useEHT: " << mUseEHTTrigs << " have EHT? " << haveEHTTrig <<endl;
495 
496  if(1 && (nPrimV>mVertexNumber) && (!mUseEHTTrigs || haveEHTTrig )) { // copy vertex info
497  StMuPrimaryVertex* V= muDst->primaryVertex(mVertexNumber);// select highest rank vertex
498  assert(V);
499  const StThreeVectorF &r=V->position();
500  vtxZ=r.z();
501  // cout <<"vtxZ: " << vtxZ <<endl;
502  const StThreeVectorF &er=V->posError();
503  float rank=V->ranking();
504 
505  //printf("primVert Z=%.2f ±%.2f rank=%5.1e (nVert=%d) \n",r.z(),er.z() ,rank, nPrimV);
506  // myJFgtEve->vertRank=rank;
507  vtxRank=rank;
508  vtxZ=r.z();
509  if(rank>0) { // use the vertex
510  // myJFgtEve->vertPos=TVector3(r.x(),r.y(),r.z());
511  // myJFgtEve->vertErr=TVector3(er.x(),er.y(),er.z());
512  hIpZEv->Fill(vtxZ);
513  }
514  else
515  {
516 #ifdef USE_VTX
517  return false; //primary vertex is not good...
518 #endif
519  }
520 
521  }
522  else{
523  vtxRank=-999;
524  }
525  // if(fabs(ipZ)>20)
526  // return false;
527  // cout <<" found z vertex: " << ipZ <<endl;
528  }
529  }
530  else
531  {
532  cout <<"no muDST!!!" <<endl;
533  }
534 
535  if( muDst ){
536  TClonesArray *fgtClusters = muDst->fgtArray( muFgtClusters );
537  TClonesArray *fgtStrips=muDst->fgtArray(muFgtStrips);
538  TClonesArray *fgtStripAssoc=muDst->fgtArray(muFgtStripAssociations );
539  TClonesArray *fgtAdc=muDst->fgtArray(muFgtAdcs);
540  // cout <<"got mdsts" <<endl;
541  if(fgtStripAssoc && fgtClusters && fgtStrips && fgtAdc)
542  {
543 
544  ierr = kStOk;
545  Int_t nAssoc=fgtStripAssoc->GetEntriesFast();
546  Int_t nClus=fgtClusters->GetEntriesFast();
547  Int_t nStrips=fgtStrips->GetEntriesFast();
548  Int_t nAdc=fgtAdc->GetEntriesFast();
549  // cout <<"there are " << nAssoc <<" associations" <<endl;
550  Int_t oldClusIdx=-1;
551  Int_t rdo, arm, apv, chan;
552  Int_t geoId;
553  Int_t clusKey=0;
554  Short_t quad, disc, stripNum;
555  Char_t layer;
556  StFgtHit* pFgtHit=0;
557  for( Int_t i = 0; i < nAssoc; ++i )
558  {
559  StMuFgtStripAssociation* assoc = static_cast< StMuFgtStripAssociation* >( (*fgtStripAssoc)[i] );
560  if( assoc )
561  {
562  //only construct clusters for which we have the strips...
563  Int_t clusIdx=assoc->getClusIdx();
564  if(oldClusIdx!=clusIdx) //looking at new clusters
565  {
566  //construct new cluster
567  oldClusIdx=clusIdx;
568  if(pFgtHit)
569  hitCollectionPtr[disc]->getHitVec().push_back(pFgtHit);
570  StMuFgtCluster* clus = static_cast< StMuFgtCluster* >( (*fgtClusters)[clusIdx] );
571  Int_t clusCentGeoId=clus->getCentralStripGeoId();
572  // cout <<" looking at : " << clusCentGeoId <<endl;
573  Float_t clusCharge=clus->getCharge();
574  Float_t R=clus->getR();
575  Float_t Phi=clus->getPhi();
576  Float_t Z=getLocDiscZ(disc);
577  Float_t ErrR=clus->getErrR();
578  Float_t ErrPhi=clus->getErrPhi();
579  Float_t ErrZ=0.0;
580  StFgtGeom::decodeGeoId(clusCentGeoId,disc, quad, layer, stripNum);
581  pFgtHit=new StFgtHit(clusKey,clusCentGeoId,clusCharge, disc, quad, layer, R, ErrR,Phi, ErrPhi,Z,ErrZ);
582  clusKey++;
583  pFgtHit->setChargeUncert(clus->getChargeUncert());
584 
585  pFgtHit->setEvenOddChargeAsy(clus->getEvenOddChargeAsy());
586  pFgtHit->setMaxTimeBin(clus->getMaxTimeBin());
587  pFgtHit->setMaxAdc(clus->getMaxAdc());
588  pFgtHit->setNstrip(clus->getNumStrips());//should check if that corresponds to the number of strips...
589  //not in mdst??
591  }
592  else
593  {
594 
595  }
596  Int_t stripIdx=assoc->getStripIdx();
597  StMuFgtStrip* strip = static_cast< StMuFgtStrip* >( (*fgtStrips)[stripIdx] );
598  geoId=strip->getGeoId();
599  Float_t stripCharge=strip->getCharge();
600  mDb->getElecCoordFromGeoId(geoId, rdo,arm,apv,chan);
601  StFgtGeom::decodeGeoId(geoId,disc, quad, layer, stripNum);
602  Int_t elecId = StFgtGeom::encodeElectronicId( rdo, arm, apv, chan );
603  //strips are dynamically created by the strip collection
604  StFgtStrip* stripPtr = stripCollectionPtr[disc]->getStrip( elecId );
605  stripPtr->setGeoId(geoId);
606  stripPtr->setCharge(stripCharge);
607  stripPtr->setElecCoords(rdo,arm,apv,chan);
608  Double_t ped = mDb->getPedestalFromElecId( elecId );
609  Double_t pedErr = mDb->getPedestalSigmaFromElecId( elecId );
610  stripPtr->setPed(ped);
611  stripPtr->setPedErr(pedErr);
612  stripPtr->setChargeUncert(strip->getChargeUncert());
613  Int_t seedType=strip->getClusterSeedType();
614  stripPtr->setClusterSeedType(seedType);
615  if(seedType>=kFgtSeedType1&& seedType<=kFgtSeedType5 )
616  {
617  pFgtHit->setSeedType(seedType);
618  }
619  //fill in strip info
620  //fill in adc info
621  for(Int_t iAdc=strip->getAdcStartIdx();iAdc<strip->getAdcStartIdx()+strip->getNumSavedTimeBins();iAdc++)
622  {
623  if(iAdc>=0 && (iAdc<nAdc))
624  {
625  StMuFgtAdc* adc=0;
626  adc=static_cast< StMuFgtAdc* >((*fgtAdc)[iAdc]);
627  stripPtr->setAdc(adc->getAdc(),adc->getTimeBin());
628  }
629  }
630  //even though the "strips" container can be invalidaded by added to it, the *it is a pointer to a StFgtStrip, so should stay
631  (pFgtHit->getStripWeightMap())[stripPtr]=1;
632  }
633  else
634  {
635  cout <<"no assoc..." << assoc <<endl;
636  }
637  }
638  //put last cluster in...
639  if(pFgtHit)
640  hitCollectionPtr[disc]->getHitVec().push_back(pFgtHit);
641  }
642  else
643  {
644  //doesn't make sense to continue w/o clusters/strips
645  return kStErr;
646  }
647  }
648 
649 return ierr;
650 };
651 
653 {
654 
655  Char_t layer;
656  Short_t quad, disc, strip;
657  Double_t ordinate, lowerSpan, upperSpan;
658  Int_t iValCluR[4];
659  Int_t iValCluP[4];
660  for(int iq=0;iq<4;iq++)
661  {
662  iValCluR[iq]=0;
663  iValCluP[iq]=0;
664  }
665  for(int iDx=0;iDx<6;iDx++)
666  {
667  for(vector<generalCluster>::iterator it=(*pClusters[iDx]).begin();it!=(*pClusters[iDx]).end();it++)
668  {
669  StFgtGeom::getPhysicalCoordinate(it->centralStripGeoId,disc,quad,layer,ordinate,lowerSpan,upperSpan);
670  if(layer=='R')
671  iValCluR[quad]++;
672  else
673  iValCluP[quad]++;
674  }
675  for(int iQ=0;iQ<4;iQ++)
676  {
677  hNumClustersR[iDx*4+iQ]->Fill(iValCluR[iQ]);
678  hNumClustersP[iDx*4+iQ]->Fill(iValCluP[iQ]);
679  }
680  }
681  for(int iDx=0;iDx<6;iDx++)
682  {
683  for(int iQ=0;iQ<4;iQ++)
684  {
685 
686  int iValPulseP=0;
687  int iValChargeP=0;
688  int iValPulseR=0;
689  int iValChargeR=0;
690  Char_t layer;
691  Short_t quad, disc, strip;
692  Double_t ordinate, lowerSpan, upperSpan;
693  for(vector<generalStrip>::iterator it=pStrips[iDx*4+iQ].begin();it!=pStrips[iDx*4+iQ].end();it++)
694  {
695  StFgtGeom::getPhysicalCoordinate(it->geoId,disc,quad,layer,ordinate,lowerSpan,upperSpan);
696  if(validPulse((*it)))
697  {
698  if(layer=='P')
699  iValPulseP++;
700  else
701  iValPulseR++;
702  }
705  if(it->charge>1000)
706  {
707  if(layer=='P')
708  iValChargeP++;
709  else
710  iValChargeR++;
711  }
712  }
713  hNumPulsesR[iDx*4+iQ]->Fill(iValPulseR);
714  hNumPulsesP[iDx*4+iQ]->Fill(iValPulseP);
715  hNumChargesR[iDx*4+iQ]->Fill(iValChargeR);
716  hNumChargesP[iDx*4+iQ]->Fill(iValChargeP);
717  // cout <<"disk: " << iDx+1<< " quad: " << iQ << " has " <<iValPulse <<" valid pulses and " << iValCharge <<" valid charges " <<endl;
718  }
719  }
720 }
721 
722 Bool_t StFgtGeneralBase::arePointsMatched(vector<generalCluster>::iterator c1, vector<generalCluster>::iterator c2)
723 {
724  Float_t tUncert1;
725  Float_t tCharge1;
726 
727  Float_t tUncert2;
728  Float_t tCharge2;
729 
730  if(c1->clusterCharge<20 || c2->clusterCharge<20)
731  return false;
732  if(c1->clusterCharge<c2->clusterCharge)
733  {
734  tCharge1=c2->clusterCharge;
735  tUncert1=c2->clusterChargeUncert;
736  tCharge2=c1->clusterCharge;
737  tUncert2=c1->clusterChargeUncert;
738  }
739  else
740  {
741  tCharge1=c1->clusterCharge;
742  tUncert1=c1->clusterChargeUncert;
743  tCharge2=c2->clusterCharge;
744  tUncert2=c2->clusterChargeUncert;
745  }
746 
747 
748  if(((tCharge1/tCharge2) <chargeMatchCut) ||((tCharge1-tUncert1)/(tCharge2+tUncert2))<chargeMatchCut)
749  return true;
750  else
751  return false;
752 }
753 
754 void StFgtGeneralBase::checkMatches()
755 {
756  // cout <<"checkmatches.." <<endl;
757  for(int iDx=0;iDx<6;iDx++)
758  {
759  Int_t numMatched=0;
760  Int_t numNotMatched=0;
761  if((*pClusters[iDx]).size()<2)
762  continue;
763  for(vector<generalCluster>::iterator it=(*pClusters[iDx]).begin();it!=((*pClusters[iDx]).end()-1);it++)
764  {
765 
766  // if(it->hasMatch)
767  // continue;
768  Char_t layer=it->layer;
769  for(vector<generalCluster>::iterator it2=it+1;it2!=(*pClusters[iDx]).end();it2++)
770  {
771  if(it2->layer==layer)
772  continue;
773  if(it->clusterCharge<100 || it2->clusterCharge<100)
774  continue;
775  // if(it2->hasMatch)//can have two matches?
776  // continue;
777 
778  if(arePointsMatched(it,it2))
779  {
780  it->hasMatch=true;
781  it2->hasMatch=true;
782  }
783 
784  }
785 
786  }
787  for(vector<generalCluster>::iterator it=(*pClusters[iDx]).begin();it!=(*pClusters[iDx]).end();it++)
788  {
789  if(it->hasMatch)
790  numMatched++;
791  else
792  numNotMatched++;
793  }
794  clusWChargeMatch->Fill(numMatched);
795  clusWOChargeMatch->Fill(numNotMatched);
796  // cout <<"disk: " << iDx<<" found " << numMatched <<" clusters and " << numNotMatched << " clusters that were not matched" <<endl;
797  }
798 
799 }
800 
801 void StFgtGeneralBase::fillFromEvent(Bool_t fillFromEv) //default, no, use mDsts
802 {
803  m_fillFromEvent=fillFromEv;
804  // cout <<"m_fillFromEvent: " << m_fillFromEvent <<endl;
805 }
806 
807 void StFgtGeneralBase::doLooseClustering()
808 {
809  for(int iDx=0;iDx<6;iDx++)
810  {
811  if(iDx==3) //disk 3 is noisy at high HV
812  continue;
813  Int_t stripCounter=0;
814  for(int iQ=0;iQ<4;iQ++)
815  {
816  cout <<" loose clustering in disk: " << iDx << " quad: " << iQ <<" we have: " << (*pClusters[iDx]).size() <<" clusters " <<endl;
817  for(vector<generalStrip>::iterator it=pStrips[iDx*4+iQ].begin();it!=pStrips[iDx*4+iQ].end();it++)
818  {
819  //nodead strips
820  if(it->charge > 5*it->chargeUncert && it->seedType==kFgtSeedTypeNo)
821  {
822  //implement seedtype3
823  Double_t pedErr=it->pedErr;
824  // if(pStrip->getAdc(0) <3*ped && numHighBins==1 && peakAdc > pStrip->getAdc(6)&& numHighBinsAfterLeadingEdge>=1&& numAlmostHighBins>=2)
825  Int_t numHighBins=0;
826  Int_t numAlmostHighBins=0;
827  Int_t peakAdc=-9999;
828  for(int i=0;i<7;i++)
829  {
830  if(i>=2 && i<=5)
831  {
832  if(it->adc[i]>3*pedErr)
833  numAlmostHighBins++;
834  }
835  if(it->adc[i]>peakAdc)
836  peakAdc=it->adc[i];
837  if(it->adc[i]> 5*pedErr)
838  numHighBins++;
839  }
840 
841  // if(!(it->adc[0]<3*pedErr && numHighBins>=1 && peakAdc> it->adc[6] && numAlmostHighBins>=2) )
842  // continue;
843  //not cluster midpoint
844  Char_t layerPrv, layerNext, layer;
845  Double_t posR, posPhi;
846  Int_t geoId=it->geoId;
847  Short_t quad, disc, strip;
848  Double_t ordinate, lowerSpan, upperSpan;
849  Double_t discZ=getLocDiscZ(disc);
850  Int_t clusterSize=3;
851  StFgtGeom::getPhysicalCoordinate(it->geoId,disc,quad,layer,ordinate,lowerSpan,upperSpan);
852  if((it+1)<pStrips[iDx*4+iQ].end())
853  StFgtGeom::getPhysicalCoordinate((it+1)->geoId,disc,quad,layerNext,ordinate,lowerSpan,upperSpan);
854  if((it-1)>=pStrips[iDx*4+iQ].begin())
855  StFgtGeom::getPhysicalCoordinate(it->geoId,disc,quad,layerPrv,ordinate,lowerSpan,upperSpan);
856 
857  if((it+1)<pStrips[iDx*4+iQ].end() && layerNext==layer && (it+1)->charge > it->charge)
858  continue;
859 
860  Double_t clusterCharge=it->charge;
861  if((it+1)<pStrips[iDx*4+iQ].end() && (layer==layerNext))
862  clusterCharge+=(it+1)->charge;
863  if((it-1)>=pStrips[iDx*4+iQ].begin() && (layer==layerPrv))
864  clusterCharge+=(it-1)->charge;
865 
866  StFgtGeom::decodeGeoId(geoId,disc, quad, layer, strip);
867  StFgtGeom::getPhysicalCoordinate(it->geoId,disc,quad,layer,ordinate,lowerSpan,upperSpan);
868  if( layer == 'R' ){
869  posR = ordinate;
870  posPhi = 0.5*(upperSpan + lowerSpan);
871  } else {
872  posPhi=ordinate;
873  posR = 0.5*(upperSpan + lowerSpan); // mid point of the strip
874  };
875  posPhi+=StFgtGeom::phiQuadXaxis(quad);
876 
877  pClusters[iDx]->push_back(generalCluster(geoId,layer,discZ,posPhi,posR,quad,disc,strip, clusterSize, clusterCharge,0.0));
878  mapGeoId2Cluster[geoId]=(pClusters[iDx]->size()-1);
879  (*pClusters[disc])[mapGeoId2Cluster[geoId] ].centerStripIdx=stripCounter;
880  (*pClusters[disc])[mapGeoId2Cluster[geoId] ].maxAdc=it->maxAdc;
881  //don't care for now
882  (*pClusters[disc])[mapGeoId2Cluster[geoId] ].maxAdcInt=it->maxAdc;
883  }
884  stripCounter++;
885  }
886  }
887  }
888 
889 }
890  const Int_t StFgtGeneralBase::trigID[3]={430315,430313,430312};
891 
892 Float_t StFgtGeneralBase::chargeMatchCut=1.5;
893 ClassImp(StFgtGeneralBase);
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
static TClonesArray * fgtArray(int type)
returns pointer to the n-th TClonesArray from the fgt arrays
Definition: StMuDst.h:293
Int_t fillFromMuDst(StFgtCollection &)
Definition: Stypes.h:44
Collection of trigger ids as stored in MuDst.
Definition: Stypes.h:41