StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBarrelMonitorMaker.cxx
1 // *-- Author : Jan Balewski
2 //
3 // $Id: StBarrelMonitorMaker.cxx,v 1.5 2012/12/12 22:05:09 fisyak Exp $
4 #ifdef __APPLE__
5 #include <sys/types.h>
6 #endif
7 
8 #include <TFile.h>
9 #include <TH1.h>
10 #include <TH2.h>
11 #include <TH3.h>
12 #include <StMessMgr.h>
13 
14 #include "StBarrelMonitorMaker.h"
15 #include "StJanBarrelDbMaker.h"
16 #include "JanBprsEveA.h"
17 #include "BprsCapPolygraph.h"
18 #include "BarrelMipCalib.h"
19 
20 #include "StMuDSTMaker/COMMON/StMuEvent.h"
21 #include "StMuDSTMaker/COMMON/StMuDst.h"
22 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
23 
24 #include "StEmcRawMaker/defines.h"
25 #include "StEmcUtil/geometry/StEmcGeom.h"
26 
27 #include "StDetectorDbMaker/St_tpcGasC.h"
28 #include "St_db_Maker/St_db_Maker.h"
29 #include "StEmcUtil/database/StEmcDecoder.h"
30 
31 
32 #include "StEventTypes.h"
33 #include "StMcEventTypes.hh"
34 #include "StMcEvent.hh"
35 
36 
37 ClassImp(StBarrelMonitorMaker)
38 
39 //________________________________________________
40 //________________________________________________
41 StBarrelMonitorMaker::StBarrelMonitorMaker( const char* self ): StMaker(self){
42 
43  cTile[0]='T'; cTile[1]='P';
44  cTile4[0]="BTOW"; cTile4[1]="BPRS";
45 
46  nInpEve=nAcceptEve=nTrigEve=nCorrEve= mGeantEveInp=0;
47 
48  setHList(0);
49  setTrigIdFilter(0);
50  setMC(0);
51 
52  mMappB=0;
53  hBprs3D=0;// special very large 3D histo for BPRS cap monitoring
54 
55  setBprsHisto(1);
56  setCalibPass(0);
57 }
58 
59 //________________________________________________
60 //________________________________________________
61 Int_t
62 StBarrelMonitorMaker::Init(){
63 
64  assert(HList);
65  initHistos();
66 
67  mBtowGeom = StEmcGeom::instance("bemc");
68  mBprsGeom = StEmcGeom::instance("bprs");
69  mSmdEGeom = StEmcGeom::instance("bsmde");
70  mSmdPGeom = StEmcGeom::instance("bsmdp"); // needed only to map m-s-e --> softID
71 
72  mMuDstMaker = (StMuDstMaker*)GetMaker("MuDst"); assert(mMuDstMaker);
73  mJanDbMaker = (StJanBarrelDbMaker*)GetMaker("janBarrelDb"); assert(mJanDbMaker);
74 
75  bprsPolygraph=new BprsCapPolygraph(HList, mJanDbMaker) ;
76  bprsPolygraph->setCut(50, 0.98,1,0.1);
77  bprsPolygraph->print();
78 
79  mipCalib=new BarrelMipCalib(HList, mJanDbMaker, mMuDstMaker) ;
80  mipCalib->setCut(60.,0.35,1.3,0.51, 3.3, 1.0, 180);
81  // zV, pT, eta, nFit, dedx, zMargin, Rxy
82  mipCalib->print();
83 
84  LOG_INFO<<Form("::Init() filter trigID=%d done", trigID)<<endm;
85  return StMaker::Init();
86 }
87 
88 //________________________________________________
89 //________________________________________________
90 Int_t
91 StBarrelMonitorMaker::InitRun(int runNo){
92  LOG_INFO<<Form("::InitRun(%d) start",runNo)<<endm;
93  St_db_Maker* mydb = (St_db_Maker*) StMaker::GetChain()->GetMaker("StarDb");
94  assert(mydb);
95 
96  // this is how BTOW mapping is accesible
97  mMappB = new StEmcDecoder(mydb->GetDateTime().GetDate(),mydb->GetDateTime().GetTime());
98  float airPres=St_tpcGasC::instance()-> barometricPressure();
99  LOG_INFO<<Form("::InitRun(%d) AirPressure=%.2f",runNo, airPres)<<endm;
100  if(runNo==1000000) {
101  LOG_WARN<<Form("::InitRun(%d) ??? , it is OK for M-C ",runNo)<<endm;
102  }
103 
104  LOG_INFO<<Form("::InitRun() algo params: bprsHisto=%d calibPass=%d (bits)",
105  par_bprsHisto,par_calibPass
106  )<<endm;
107  return kStOK;
108 }
109 
110 //________________________________________________
111 //________________________________________________
112 Int_t
114 
115  gMessMgr->Message("","I") <<GetName()<<"::Finish()\n inputEve="<<nInpEve<<" trigFilterEve="<<nTrigEve<<" nCorrEve="<<nCorrEve<<" nAcceptEve="<<nAcceptEve<<endm;
116  return kStOK;
117 }
118 
119 //________________________________________________
120 //________________________________________________
121 void
122 StBarrelMonitorMaker::Clear(const Option_t*){
123  eventID=-999;
124  janEve.clear();
125  for( int icr=0; icr <mxBprsCrate;icr++) janBprsEveA[icr].clear();
126 }
127 
128 //________________________________________________
129 //________________________________________________
130 //________________________________________________
131 Int_t
133  nInpEve++;
134  StMuEvent* muEve = mMuDstMaker->muDst()->event();
135 
136  eventID=muEve->eventId();
137  janEve.id=eventID;
138 
139  int nPrimV=mMuDstMaker->muDst()->numberOfPrimaryVertices();
140 
141  LOG_INFO <<GetName()<<"\n\n::Make()================ isMC="<<isMC<<" eveID="<<eventID<<" nInpEve="<<nInpEve<<" nPrimV="<<nPrimV<<endm;
142 
143 
144  vector<unsigned int> trgL=mMuDstMaker->muDst()->event()->triggerIdCollection().nominal().triggerIds();
145  printf("trigL len=%d\n",int(trgL.size()));
146  uint ii;
147  for( ii=0;ii<trgL.size();ii++) printf("ii=%d trigID=%d\n",ii,trgL[ii]);
148  if (mMuDstMaker->muDst()->event()->triggerIdCollection().nominal().isTrigger(19)) return kStOK; // drop bbc-fast events
149 
150 
151  // printf("trigOK\n");
152  // nTrigEve++;
153 
154 
155  unpackStTiles(kBTow);
156  unpackStTiles(kBPrs);
157 
158  populateBprsEveA();
159 
160  // ...... check for BPRS capID corruption .....
161  for(int bprsCrateID=0; bprsCrateID<mxBprsCrate; bprsCrateID++)
162  // int bprsCrateID=2;
163  {
164  JanBprsEveA &bprsEve=janBprsEveA[bprsCrateID];
165  bprsPolygraph->doBaseline(bprsEve,janEve);
166  bprsPolygraph->findBestCap(bprsEve,janEve);
167  bprsPolygraph->doPedResidua(bprsEve);
168  if(par_calibPass & kPassCapFix) // do correct capID corruption
169  janEve.bprsCap[bprsCrateID]=bprsEve.getBestCapID();
170  }
171  //if(nInpEve<3) janEve.print(2);
172  calibrateTiles(kBPrs);
173  calibrateTiles(kBTow);
174 
175 
176  //
177 
178  mipCalib->search(janEve); // full analysis
179  // mipCalib->searchEtaBin20(janEve); // just last eta bin location
180 
181  return kStOK;
182 }
183 
184 
185 
186 //___________________ _____________________________
187 //________________________________________________
188 StBarrelMonitorMaker::~StBarrelMonitorMaker(){
189 
190 }
191 
192 //___________________ _____________________________
193 //________________________________________________
194 void
195 StBarrelMonitorMaker::saveHisto(TString fname){
196  TString outName=fname+".hist.root";
197  TFile f( outName,"recreate");
198  assert(f.IsOpen());
199  printf("HHH %d histos are written to '%s' ...\n",HList->GetEntries(),outName.Data());
200 
201  HList->Write();
202  f.Close();
203 
204 }
205 
206 //________________________________________________
207 //________________________________________________
208 void
209 StBarrelMonitorMaker::unpackStTiles(int ibp){
210  StEvent *mEvent = (StEvent*)StMaker::GetChain()-> GetInputDS("StEvent");
211  assert(mEvent);
212 
213  //......................... BTOW or BPRS ....................
214  //use StEvent as default to get simulation right in BEMC
215  StEmcCollection *emc = mEvent->emcCollection();
216  assert (emc);
217 
218  int jBP=BTOW;
219  StEmcDetector* detector=emc->detector(kBarrelEmcTowerId);
220  StEmcGeom *geomB=mBtowGeom;
221  if( ibp==kBPrs) {// change pointers for preshower
222  jBP=BPRS;
223  geomB=mBprsGeom;
224  detector=emc->detector(kBarrelEmcPreShowerId);
225  }
226 
227  if(!detector) {
228  printf("no %s data, nInpEve=%d\n",cTile4[ibp],nInpEve);
229  return;
230  }
231 
232  // for BPRS unpack caps and store locally
233  if(ibp==kBPrs ) {
234  for(int icr=0;icr<mxBprsCrate;icr++) {
235  StEmcModule* module = detector->module(2+icr*30);assert(module);
236  StSPtrVecEmcRawHit& rawHit=module->hits();
237  if(rawHit.size()<=0) {
238  printf("ss icr=%d n=%dL, ABORT BpRS for this event\n",icr,int(rawHit.size()));
239  return ;
240 }
241  assert(rawHit.size()>0);
242  janEve.bprsCap[icr]= rawHit[10]->calibrationType();
243  // tmp
244  if(icr==3) janEve.bprsCap[icr]= rawHit[32]->calibrationType();
245 
246  }
247  }
248 
249  // unpack raw data and store it locally in an array
250  for(Int_t m = 1; m <= 120; ++m) {
251  StEmcModule* module = detector->module(m);
252  //printf("MMM %s m=%p mod=%d\n",cTile4[ibp],module,m);
253  if(!module) continue;
254 
255  StSPtrVecEmcRawHit& rawHit=module->hits();
256  // printf("HHH n=%d\n",rawHit.size());
257  for(UInt_t k = 0; k < rawHit.size(); ++k){
258  int id;
259 
260  Int_t m=rawHit[k]->module();
261  Int_t e=rawHit[k]->eta();
262  Int_t s=abs(rawHit[k]->sub());
263  float rawAdc=rawHit[k]->adc()+0.5;// return middle of the bin
264 
265  //Get software tower id to get DaqID
266  geomB->getId(m,e,s,id);
267 
268 #if 0 // tmp for Matt, to QA new mapping
269  if(ibp==kBPrs ){
270  int id1=(int)mJanDbMaker->bprsReMap()->GetBinContent(id);
271  printf("BPRSX %d %d %d %d\n",nInpEve-1,id1,rawHit[k]->adc(),rawHit[k]->calibrationType());
272  }
273  // end tmp
274 #endif
275 
276  assert(id>=1);
277  assert(id<=mxBtow);
278  janEve.rawAdcTile[ibp][id-1]=rawAdc;
279  // if(id%20==7)
280  // if(ibp==kBPrs && (id>650 && id<710)) printf("unpack %s hit=%d softid=%d, m=%d rawADC=%.1f\n",cTile4[ibp],k,id,m,rawAdc);
281  }
282  }// end of module loop
283 
284  janEve.tileIn[ibp]=1; // tag data block as delivered
285 
286  assert(!isMC); // verify peds for MC
287 }
288 //________________________________________________
289 //________________________________________________
290 void
291 StBarrelMonitorMaker::calibrateTiles(int ibp){
292  // printf("ZZ %d %d\n",ibp, janEve.tileIn[ibp]);
293  if(janEve.tileIn[ibp]==0) return; // no data in this event
294 
295  for(int id0=0; id0<mxBtow; id0++) {
296  int id=id0+1;
297  int crateID=0;
298 
299  int capID=0;
300  int stat =mJanDbMaker->statTile(ibp,id);
301 
302  if(ibp==kBPrs ) {
303  crateID= mJanDbMaker->bprsCrate(id);
304  capID=janEve.bprsCap[crateID]; //fix capID corruption in 2008
305  }
306 
307  float ped =mJanDbMaker->pedTile(ibp,id,capID);
308  float rawAdc =janEve.rawAdcTile[ibp][id0];
309 
310  // if(ibp==kBPrs) printf("ss id=%d stat=%d rawAdc=%.1f\n", id,stat,rawAdc);
311  if(ibp==kBPrs && rawAdc>100 && rawAdc<300){
312  //accumulate pedestals vs. capID similat to Tonko's on-line approach
313  hTonko0->Fill(id,capID,1.);
314  hTonko1->Fill(id,capID,rawAdc);
315  hTonko2->Fill(id,capID,rawAdc*rawAdc);
316  }
317 
318  if(!(par_calibPass & kPassPedSub)) {
319  hTile[ibp]->Fill(id,rawAdc);
320  if(par_bprsHisto==2) hBprs3D->Fill(id,rawAdc,capID);
321  }
322 
323  if(par_calibPass==0) continue; // no swap info loaded in this mode
324 
325  //------ TMP ----- apply BPRS & BTOW swap only for ped-corrected ADC data
326  if(ibp==kBTow) {
327  id=(int)mJanDbMaker->btowReMap()->GetBinContent(id);
328  } else if(ibp==kBPrs) {
329  id=(int)mJanDbMaker->bprsReMap()->GetBinContent(id);
330  } else assert(1==2);
331 
332  // below use only 'id' for indexing to pick up this swaping
333 
334 
335  if(stat) {
336  janEve.statTile[ibp][id-1]=stat; // is bad
337  continue;
338  } else {
339  janEve.statTile[ibp][id-1]=0; // is good
340  }
341 
342  float adc=rawAdc-ped;
343  janEve.adcTile[ibp][id-1]= adc;
344 
345  if(par_calibPass & kPassPedSub){
346  hTile[ibp]->Fill(id,adc);
347  if(ibp==kBPrs){ // later add alos BTOW histos per crate, fix it
348  hBprsA[crateID]->Fill(adc);
349  if(par_bprsHisto==2) hBprs3D->Fill(id,adc,capID);
350  }
351  }
352 
353  //..... energy calibration goes here, later
354  //...
355 
356  } // end of data loop
357 
358 
359 }
360 
361 //________________________________________________
362 //________________________________________________
363 void
364 StBarrelMonitorMaker::populateBprsEveA(){
365 
366  if(janEve.tileIn[kBPrs]==0) return; // no data in this event
367 
368  for( int icr=0; icr <mxBprsCrate;icr++) {
369  int capID=janEve.bprsCap[icr];
370  janBprsEveA[icr].set(capID,icr,eventID);
371  }
372 
373  int ibp=kBPrs;
374  for(int id0=0; id0<mxBtow; id0++) {
375  int id=id0+1;
376  int icr=mJanDbMaker->bprsCrate(id);
377  float rawAdc =janEve.rawAdcTile[ibp][id0];
378  janBprsEveA[icr].addRawValue(id,rawAdc);
379  //printf("id=%d, icr=%d \n",id,icr);
380  }
381 
382 }
383 
384 
385 //---------------------------------------------------
386 // $Log: StBarrelMonitorMaker.cxx,v $
387 // Revision 1.5 2012/12/12 22:05:09 fisyak
388 // add sys/types.h include for APPLE
389 //
390 // Revision 1.4 2009/08/25 16:17:48 fine
391 // fix the compilation issues under SL5_64_bits gcc 4.3.2
392 //
393 // Revision 1.3 2009/08/25 16:08:04 fine
394 // fix the compilation issues under SL5_64_bits gcc 4.3.2
395 //
396 // Revision 1.2 2009/02/04 20:33:32 ogrebeny
397 // Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
398 //
399 // Revision 1.1 2008/11/24 23:06:35 balewski
400 // start
401 //
StMuDst * muDst()
Definition: StMuDstMaker.h:425
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
Definition: Stypes.h:40