StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPmdReadMaker.cxx
1 /***************************************************************************
2  *$Id: StPmdReadMaker.cxx,v 1.39 2017/04/26 19:55:17 perev Exp $
3  *
4  * StPmdReadMaker
5  *
6  * Author: Supriya Das and Subhasis Chattopadhyay
7  ***************************************************************************
8  *
9  * Description: Reading PMD data and filling hits for StEvent
10  **************************************************************************
11  *$Log: StPmdReadMaker.cxx,v $
12  *Revision 1.39 2017/04/26 19:55:17 perev
13  *Hide m_DataSet
14  *
15  *Revision 1.38 2011/08/17 11:45:51 rashmi
16  *year==12 27GeV BadChains entered
17  *
18  *Revision 1.37 2011/06/01 16:45:28 rashmi
19  *year==12 BadChains entered
20  *
21  *Revision 1.36 2011/04/26 13:14:27 rashmi
22  *mVmeCond,BadChain info changed for year==12 data
23  *
24  *Revision 1.35 2010/07/06 16:30:45 rashmi
25  *Calibration updates for run10
26  *
27  *Revision 1.34 2010/06/30 04:47:23 subhasis
28  *reader fixed for reading daq files earlier than 2009 runs
29  *
30  *Revision 1.33 2010/05/31 22:11:09 rashmi
31  *Edep of Pmdhit now hold calibrated ADC
32  *
33  *Revision 1.32 2010/04/16 12:09:40 rashmi
34  *Modifcation for new DAQ
35  *
36  *Revision 1.31 2010/04/16 12:04:13 rashmi
37  *Modifcation for new DAQ
38  *
39  *Revision 1.30 2008/11/18 12:47:11 rashmi
40  *BadChains for dAu added
41  *
42  *Revision 1.29 2008/01/15 19:32:22 perev
43  *No HOT CELLS, return with error flag
44  *
45  *Revision 1.28 2007/12/02 10:07:39 rashmi
46  *Changing SMChain_GNF from MPVFactor to MeanFactor
47  *
48  *Revision 1.27 2007/11/17 15:50:46 rashmi
49  *correcting setting of mCalibFlag
50  *
51  *Revision 1.26 2007/11/02 11:03:00 rashmi
52  *Storing gains with hits, not applying gain calibration
53  *
54  *Revision 1.25 2007/10/26 18:13:17 rashmi
55  *fixed some warnings
56  *
57  *Revision 1.24 2007/09/06 06:35:30 genevb
58  *Small refinements to the BadChain fix
59  *
60  *Revision 1.23 2007/09/06 05:30:52 subhasis
61  *Subhasis: BadChain fix to avoid cucu crash
62  *
63  *Revision 1.22 2007/09/05 03:41:42 genevb
64  *Attribute check was in the wrong place
65  *
66  *Revision 1.21 2007/09/05 03:19:45 genevb
67  *Use attribute pmdRaw
68  *
69  *Revision 1.20 2007/08/31 10:50:12 rashmi
70  *Added routines to read badchains,HotCells,Cell_GNF,SMChain_GNF,Modified VMEcondition&ApplyMapping(subhasis)
71  *
72  *Revision 1.19 2007/07/12 19:52:05 fisyak
73  *Add includes for ROOT 5.16
74  *
75  *Revision 1.18 2007/04/28 17:56:37 perev
76  *Redundant StChain.h removed
77  *
78  *Revision 1.17 2007/04/26 04:14:27 perev
79  *Remove StBFChain dependency
80  *
81  *Revision 1.16 2006/02/16 21:36:08 perev
82  *No delete pmdCollection. It is deleted in Clear()
83  *
84  *Revision 1.15 2005/12/07 19:46:39 perev
85  *EndCrashFix
86  *
87  *Revision 1.14 2005/01/27 13:08:51 subhasis
88  *chaged to read 2005 data
89  *
90  *Revision 1.13 2004/09/22 19:24:56 perev
91  *Leak fixed + mess with i,j indexes
92  *
93  *Revision 1.12 2004/07/12 14:45:08 subhasis
94  *QA hist added
95  *
96  *Revision 1.11 2004/07/09 12:23:03 subhasis
97  *numbering scheme adopted on CPV
98  *
99  *Revision 1.10 2004/07/09 10:40:09 subhasis
100  *channel 0 ADC made to 0, numbering scheme implemented in fillStEvent, earlier it was done on StPmdHit, in stead of StPhmdHit
101  *
102  *Revision 1.9 2004/07/09 09:01:13 subhasis
103  *numbering convention starts from 0 everywhere for filling StEvent
104  *
105  *Revision 1.8 2004/06/25 10:38:00 subhasis
106  *vmecond bug fixed for 200 geV
107  *
108  *Revision 1.7 2004/04/14 15:40:41 subhasis
109  *chainno 45,46 interchanged (in hardware) issue fixed
110  *
111  *Revision 1.6 2004/03/23 08:52:22 subhasis
112  *several changes (Board Detail by hand etc) for first production
113  *
114  *Revision 1.5 2004/03/12 06:36:57 subhasis
115  *fillStEvent argument orders done properly
116  *
117  *Revision 1.4 2004/03/11 11:29:46 subhasis
118  *Changes made for PMD run config
119  *
120  *Revision 1.3 2003/12/03 11:50:29 subhasis
121  *Comment header changed by Supriya
122  *
123  ***************************************************************************
124  */
125 
126 //#include <Stiostream.h>
127 #include "Stsstream.h"
128 
129 #include "StPmdReadMaker.h"
130 #include "St_DataSetIter.h"
131 
132 #include "StDbLib/StDbManager.hh"
133 #include "StDbLib/StDbTable.h"
134 #include "StDbLib/StDbConfigNode.hh"
135 
136 #include "StGlobals.hh"
137 #include "StPmdUtil/StPmdCollection.h"
138 #include "StPmdUtil/StPmdDetector.h"
139 #include "StPmdUtil/StPmdHit.h"
140 #include "StPmdUtil/StPmdModule.h"
141 #include "StPmdUtil/StPmdGeom.h"
142 #include "StPmdUtil/StPmdDBUtil.h"
143 #include<StMessMgr.h>
144 #include "StRtsTable.h"
145 #include "RTS/src/DAQ_PMD/pmd.h"
146 
147 //#include "RTS/src/EVP_READER/pmdReader.h"
148 //
149 // Interfaces
150 //
151 // DAQ Libraries
152 #include "StDaqLib/GENERIC/EventReader.hh"
153 #include "StDaqLib/PMD/PMD_Reader.hh"
154 #include "StDAQMaker/StDAQReader.h"
155 
156 #include "TFile.h"
157 // added for StEvent
158 #include "StEvent/StEvent.h"
159 #include "StEvent/StEventTypes.h"
160 
161 //added for cleanup
162 #include "StPmdCleanConstants.h"
163 Int_t BadChainZero[25];
164 Int_t * BadChain;
165 Float_t SM_chain_factor[24][48];
166 //ofstream fout("raw_5030002.dat");
167 
168 //
169 ClassImp(StPmdReadMaker) // macro
170 //-----------------------------------------------------------------
171 
172 StPmdReadMaker::StPmdReadMaker(const char *name) : StRTSBaseMaker("pmd",name)
173 {
174  mThePmdReader=NULL;
175  mEvtPmdCollection=NULL;
176  mPmdCollection=NULL;
177  mTheDataReader=NULL;
178  mThePmdData=NULL;
179  mPmdEvent=NULL;
180  mCpvEvent=NULL;
181  mDb=NULL;
182  m_PmdCalibConst=NULL;
183  mPmdGeom = new StPmdGeom();
184  mPmdDBUtil = new StPmdDBUtil();
185  mChainTh=0;
186 
187  mCalibFlag=kFALSE;
188  // mCalibFlag=kTRUE;
189 
190  mPmdPrint=kFALSE;
191  mHotCells=NULL;
192 }
193 
194 //-----------------------------------------------------------------
195 
196 StPmdReadMaker::~StPmdReadMaker() {
197  delete mPmdGeom; mPmdGeom =0;
198  delete mPmdDBUtil; mPmdDBUtil =0;
199  mThePmdReader =0;
200  mTheDataReader=0;
201  mThePmdData =0;
202  mPmdEvent =0;
203  mCpvEvent =0;
204  mPmdCollection=0;
205  mDb=0;
206  m_PmdCalibConst=0;
207  mHotCells=0;
208 }
209 
210 //-----------------------------------------------------------------
211 
212 Int_t StPmdReadMaker::Init() {
213  if(mPmdPrint)gMessMgr->Info("StPmdReadMaker::Init()");
214  mCalibFlag = !(IAttr("pmdRaw"));
215  // mCalibFlag = (IAttr("pmdRaw"));
216  bookHist();
217 
218  return StMaker::Init();
219 }
220 //-----------------------------------------------------------------
221 
222 Int_t StPmdReadMaker::InitRun(Int_t runnr) {
223  if(mPmdPrint)gMessMgr->Info("StPmdReaderMaker::InitRun()");
224 
225  mRunNumber = runnr;
226  mPmdGeom->readBoardDetail(runnr);
227  // cout<<"PMDINITRUN*****runnr "<<runnr<<" "<<mRunNumber<<endl;
228 
229  if(mRunNumber < 5034042) mVmeCond = 1;
230  else if(mRunNumber >= 5034042 && mRunNumber < 5049020) mVmeCond = 2;
231  else if(mRunNumber >= 5049020 && mRunNumber < 6000000) mVmeCond = 3;
232  else if(mRunNumber >= 6000000 && mRunNumber < 7000000) mVmeCond = 4; // run 7 data
233  else if(mRunNumber >= 8000000 && mRunNumber < 9000000) mVmeCond = 5; // run 7 data
234  else if(mRunNumber >= 9000000) mVmeCond = 5; // run 7 data
235  // // Subhasis: 7000000 to 8000000, this was pp , PMD was absent..
236  // subhasis (25th aug 2007:) These conditions need to be checked very carefully
237 
238  // cout<<"Run Number, VME Condition : "<<mRunNumber<<" "<<mVmeCond<<endl;
239  // subhasis // to fix crash in BadChain
240  for(Int_t i=0;i<25;i++) BadChainZero[i]=0;
241 
242  ReadBadChains(runnr);
243  ReadCalibrationsConst();
244 
245  /*
246  for(int ic=1;ic<=48;ic++){
247  for(int sm = 1;sm<=24;sm++){
248  if(SM_chain_factor[sm-1][ic-1]>0)cout<<sm<<","<<ic<<","<<SM_chain_factor[sm-1][ic-1]<<endl;
249  }
250  }
251 
252  for(int ic=1;ic<=48;ic++){
253  for(int icl=0;icl<1728;icl++){
254  if(IsHot(ic,icl))fout<<"HOT "<<ic<<" "<<icl<<endl;
255  }
256  }
257  */
258 
259  return StMaker::InitRun(runnr);
260 }
261 
262 //----------------------------------------------------
263 
264 void StPmdReadMaker::ReadBadChains(Int_t runNo){
265 
266  Int_t rn,year;
267  mPmdGeom->GetRunYear(runNo,rn,year);
268  if(Debug())cout<<"runNo="<<runNo<<" year="<<year<<endl;
269  cout<<"runNo="<<runNo<<" year="<<year<<endl;
270 
271  if(year==12){
272  if(runNo>12172000){
273  BadChain = PmdClean::BadChain_y12d172;
274  }else if(runNo>12114000){
275  BadChain = PmdClean::BadChain_y12d114;
276  }else{
277  BadChain = PmdClean::BadChain_y12d0;
278  }
279  // cout<<" I have read bad chains in this loop"<<endl;
280 
281  }
282 
283  if(year==11){
284  if(runNo>11148001){
285  BadChain = PmdClean::BadChain_y10d148;
286  }else if(runNo>11105000){
287  BadChain = PmdClean::BadChain_y10d105;
288  }else if(runNo>11100000){
289  BadChain = PmdClean::BadChain_y10d100;
290  }else if(runNo>11091000){
291  BadChain = PmdClean::BadChain_y10d91;
292  }else if(runNo>11001000){
293  BadChain = PmdClean::BadChain_y10d0;
294  }
295  }
296 
297 
298  if(year==8){
299  if(runNo>8342000){
300  BadChain = PmdClean::BadChain_y8d342;
301  }else if(runNo>8143000){
302  BadChain = PmdClean::BadChain_y8d143;
303  }else if(runNo>8135000){
304  BadChain = PmdClean::BadChain_y8d135;
305  }else if(runNo>8131000){
306  BadChain = PmdClean::BadChain_y8d131;
307  }else if(runNo>8122000){
308  BadChain = PmdClean::BadChain_y8d122; // for year2007 data for day122-1\28
309  }else if(runNo>8116000){
310  BadChain = PmdClean::BadChain_y8d116; // for year2007 data for day116-1\21
311  }else if(runNo>8108000){
312  BadChain = PmdClean::BadChain_y8d108; // for year2007 data for day108-1\15
313  }else if(runNo>8102000){
314  BadChain = PmdClean::BadChain_y8d102; // for year2007 data for day102-1\07
315  }else if(runNo > 8095000){
316  BadChain = PmdClean::BadChain_y8d95; // for year2007 data for day95-100
317  }else if(runNo>8089001){
318  BadChain = PmdClean::BadChain_y8d89; // for year2007 data for day89-92
319  }else{
320  BadChain = PmdClean::BadChain_y8d0;
321  }
322  } else {
323  BadChain = BadChainZero;
324  }
325 
326  if (BadChain[0]>0 && Debug()){
327  // if (BadChain[0]>0){
328  cout<<"BadChains are ";
329  for(Int_t i=0;i<25;i++){
330  if (BadChain[i]>0) cout<<BadChain[i]<<" ";
331  }
332  cout<<endl;
333  }
334 
335 }
336 
337 //-------------------------------------------------------------------
338 /*
339 StRtsTable *StPmdReadMaker::GetNextLegacy(int sector)
340 {
341  TString pmdQuery = Form("legacy[%i]",sector);
342  // StRtsTable *daqPmdTable = GetNextLegacy();
343  StRtsTable *daqPmdTable = GetNext(pmdQuery.Data());
344  if (daqPmdTable) {
345  return daqPmdTable;
346  }
347  return 0;
348 }
349 */
350 //------------------------------------------------------------------
351  /*
352 StRtsTable *StPmdReadMaker::GetNextRaw(int sector)
353 {
354  TString pmdRawQuery = Form("raw[%i]",sector);
355  return GetNext(pmdRawQuery.Data());
356 }
357  */
358 //------------------------------------------------------------------
359 
360 Int_t StPmdReadMaker::Make() {
361 
362  if(mPmdPrint)gMessMgr->Info("StPmdReadMaker::Make()");
363  Int_t adc[2*PMD_CRAMS_MAX*2*(PMD_CRAMS_CH_MAX)];
364  Int_t rn,year;
365  mPmdGeom->GetRunYear(mRunNumber,rn,year);
366  if(Debug())cout<<"runNo="<<mRunNumber<<" year="<<year<<endl;
367 
368  // The new daq was used after 2010
369 
370  Int_t adcChCount=0;
371  // Float_t Pmdhit[50]={0.};
372  // Float_t Pmdadc[50]={0.};
373 
374  // Float_t pmdHIT=0.;
375  // Float_t pmdADC=0.;
376 
377  for (int sector=1; sector<2;++sector) {
378  // cout<<" sector = "<<sector<<endl;
379  while ( GetNextLegacy(sector) ) {
380  //
381  pmd_t* fpmd = (pmd_t*)*DaqDta()->begin();
382  Int_t nChain=0;
383  for(Int_t crate=0;crate<2;crate++) {
384  //printf("Crate %s: status %d, mode %d\n",crate==0?"Up":"Dn",fpmd->status[crate],fpmd->mode) ;
385  for(Int_t c=0;c<12;c++) {
386  for(Int_t s=0;s<2;s++) {
387  Int_t chmax = 0;
388  Int_t chain = 0;
389  for(Int_t ch=0;ch<1728;ch++) {
390  if(s==0){ nChain=c+12*crate;}
391  if(s==1){ nChain=(c+24)+12*crate;}
392  Double_t ped_mean= (double)fpmd->ped[crate][c][s][ch]/16.0;
393  Double_t ped_rms= (double)fpmd->rms[crate][c][s][ch]/16.0;
394  //Double_t ped_thr= (double)fpmd->thr[crate][c][s][ch]/16.0;
395  Int_t adc_ch = fpmd->adc[crate][c][s][ch];
396  if(adc_ch>0 && chmax<ch) {chmax = ch; chain = nChain;}
397  adc[adcChCount]=adc_ch;
398  adcChCount++;
399  // if(s==1 && ch>0 && adc_ch>0){
400  //pmdHIT++;
401  //pmdADC++;
402  //Pmdhit[nChain]++;
403  //Pmdadc[nChain]+=adc_ch;
404  // }
405  if(adc_ch>0 ||ped_mean>0){
406  chain_adc[nChain]->Fill(ch,adc_ch);
407  chain_mean[nChain]->Fill(ch,ped_mean);
408  chain_rms[nChain]->Fill(ch,ped_rms);
409 
410  // printf("CRAM %2d: side %d: ch %4d: adc %4d [ped %4.1f, rms %4.2f, thr %4.1f]\n", c,s,ch, adc_ch, ped_mean, ped_rms, ped_thr) ;
411  }
412  }
413  // cout<<"crate = "<<crate<<" c="<<c<<" s = "<<s<<" chmax="<<chmax<<" chain = "<<chain<<" boards = "<<(chmax*1.0)/64<<endl;
414  }
415  }
416  }
417  // do something
418  // int ret=mThePmdReader->getAllPmdCpvData(&adc[0]);
419  // if(ret){/*nothing*/}
420  // cout<<" I am calling applymapping"<<endl;
421  Int_t result=ApplyMapping(&adc[0]);
422  // cout<<" applymapping called"<<endl;
423  if(result!=kStOK){gMessMgr->Info("Problem in getting PMD data:ApplyMap");
424  return kStWarn;
425  }
426  }
427  //getting tofmultiplicity
428  /*
429 
430  StEvent *currevent = (StEvent*)GetInputDS("StEvent");
431  // cout<<"+++++++++++++++++++++++================+++++++++++++++++"<<endl;
432  // cout<<"getting stevent,id,pmd hit,adc "<<currevent->triggerIdCollection()->nominal()->isTrigger(270005)<<" "<<pmdHIT<<" "<<pmdADC<<endl;
433  //cout<<"+++++++++++++++++++++++================+++++++++++++++++"<<endl;
434 // if(!currevent->triggerIdCollection()->nominal()->isTrigger(260024)) continue;
435 
436  // cout<<" current event ="<<currevent<<endl;
437  // cout<<"getting ctbm "<<endl;
438  // int ctbm=currevent->triggerData()->ctbSum(0);
439 
440  StTriggerData *theData =currevent->triggerData();
441 
442  // cout<<"tofmultiplcity "<<theData->tofMultiplicity()<<endl;
443  StTriggerDetectorCollection *theTriggers =currevent->triggerDetectorCollection();
444 
445  StZdcTriggerDetector &theZdcTrg = theTriggers->zdc();
446  StBbcTriggerDetector &theBbcTrg = theTriggers->bbc();
447  StCtbTriggerDetector &theCtbTrg = theTriggers->ctb();
448  //cout<<"444"<<theZdcTrg<<" "<<theBbcTrg<<" "<<theCtbTrg<<endl;
449 
450  Float_t ZdcAdc=theZdcTrg.adcSum();
451  Int_t BbcAdc=theBbcTrg.adcSum();
452  Double_t ctb = 0;
453  for (unsigned int slat = 0; slat < theCtbTrg.numberOfSlats(); slat++) {
454  for (unsigned int tray = 0; tray < theCtbTrg.numberOfTrays(); tray++) {
455  ctb += theCtbTrg.mips(tray,slat,0);
456  }
457  }
458  Int_t CtbMult = ctb;
459  if(Debug()){cout<<"ZdcAdc="<<ZdcAdc<<" BbcAdc="<<BbcAdc<<" CtbMult="<<CtbMult<<endl;}
460 */
461 /*
462  if(pmdHIT>0){fout<<theZdcTrg.adcSum()<<" "<<theData->tofMultiplicity()<<" "<<pmdHIT<<" "<<pmdADC<<endl;
463  for(Int_t ich=24;ich<48;ich++){
464  fout<<ich<<" "<<Pmdhit[ich]<<" "<<Pmdadc[ich]<<endl;
465  Pmdhit[ich]=0.;
466  Pmdadc[ich]=0.;
467 
468  }
469  }
470 */
471  //fcout<<"ZDC , tof, pmd "<<theZdcTrg.adcSum()<<" "<<theData->tofMultiplicity()<<" "<<pmdhit<<" "<<pmdadc<<endl;
472  //pmdhit_tof->Fill(pmdHIT,theData->tofMultiplicity());
473  //pmdadc_tof->Fill(pmdADC,theData->tofMultiplicity());
474 
475  //cout<<"getting tofm "<<endl;
476  //int tofm=(StTriggerData*)(currevent->triggerData())->tofMultiplicity(0);
477  //
478  //cout<<"------------------------------------------------------------ multiplicity : tof "<<tofm<<endl;
479 
480  }
481  //#endif
482 
483  return kStOK;
484 }
485 
486 
487 Int_t StPmdReadMaker:: ApplyMapping(int *adc)
488 {
489  // Get Year of run
490  /*
491  char runfile[20];
492  sprintf(runfile,"%d",mRunNumber);
493  // Fetch from the run # the day
494  char iRun[8];
495  char iyear[8];
496  for (Int_t ik=0; ik<3; ik++)
497  {
498  iRun[ik] = runfile[ik+1];
499  }
500  iyear[0] = runfile[0];
501  Int_t year =0;
502  year=atoi(iyear);
503  */
504  Int_t rn=0; Int_t year=0;
505  mPmdGeom->GetRunYear(mRunNumber,rn,year);
506  if(Debug())cout<<"runNo="<<mRunNumber<<" year="<<year<<endl;
507  // cout<<"Applymapping:: runNo="<<mRunNumber<<" year="<<year<<" day="<<rn<<endl;
509  if(mRunNumber<1){
510  gMessMgr->Info("Run number >11 , returning from applymapping ");
511  return kStWarn;
512  }
513  mPmdGeom->readBoardDetail(mRunNumber);
514 
515  mPmdCollection = new StPmdCollection("PmdCollection");
516  AddData(mPmdCollection);
517  StPmdDetector* det0 = mPmdCollection->detector(0);
518  StPmdDetector* det1 = mPmdCollection->detector(1);
519  // cout<<"Applymapp: Run Number, VME Condition : "<<mRunNumber<<" "<<mVmeCond<<endl;
520 
521  Int_t Chain_No,supmod,row,col,SubDet=0,chtemp;
522  Int_t AddCh_Count=0;
523  Int_t orig_nhits = 0;
524  Int_t nhits=0;
525  Int_t nhits_sm[24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
526  for(Int_t SEC=0; SEC < PMD_SECTOR; SEC++){ //PMD_SECTOR = 2
527  for(Int_t CRAM=0; CRAM < PMD_CRAMS_MAX; CRAM++){ //PMD_CRAMS_MAX = 12
528  for(Int_t BLOCK=0; BLOCK < PMD_CRAMS_BLOCK; BLOCK++){//PMD_CRAMS_BLOCK = 2
529  for(Int_t CHANNEL=0; CHANNEL < PMD_CRAMS_CH_MAX; CHANNEL++){ //PMD_CRAMS_CH_MAX = 1728
530  Int_t channel=CHANNEL; // Input to apply mapping should be 0-1727.
531 
532  //Added for diffrent VME Crate conditions ////////////
533 
534  switch (mVmeCond){
535 
536  case 1:
537  {
538  if(SEC==0){
539  if(BLOCK==0)Chain_No=25+CRAM;
540  if(BLOCK==1)Chain_No=37+CRAM;
541  }
542  else break;
543  }
544  break;
545  case 2:
546  {
547  Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
548  }
549  break;
550  case 3:
551  {
552  if(SEC==0 && BLOCK==0 && CRAM==9) Chain_No = 39;
553  else if(SEC==0 && BLOCK==0 && CRAM==10) Chain_No = 40;
554  else Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
555  }
556  break;
557  case 4: // 2005 data
558  {
559  if(SEC==0 && BLOCK==0 && CRAM==5) Chain_No = 36;
560  else Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
561  }
562  break;
563  case 5: // 2006-7 data
564  {
565  // !!! this needs to be checked
566  if(SEC==0 && BLOCK==0 && CRAM==5) Chain_No = 36;
567  else Chain_No=(CRAM+1)+(SEC*PMD_CRAMS_MAX)+(BLOCK*2*PMD_CRAMS_MAX);
568  }
569  break;
570  }
571  if(mVmeCond==4){
572  // On 18th access it was found that I/P to chain 45 and 46 are interchanged,
573  // (see log book for details).
574  Int_t Chain_original=Chain_No;
575  if(Chain_original==45)Chain_No=46;
576  if(Chain_original==46)Chain_No=45;
577  //Chain_No goes from 1 to 48
578  }
579  // VME Condition Ends ///////////////////////////////////
580 
581  // Setting the SubDetector No.
582 
583  if (Chain_No >= 1 && Chain_No < 25) SubDet = 2;
584  if (Chain_No >= 25 && Chain_No <= 48) SubDet = 1;
585 
586 
587  // Apply Mapping to get the sm, row and col here
588  // initialise the refs.
589  Int_t mapp=0;
590  supmod=0;
591  row=0;
592  col=0;
593  chtemp=-1;
594 
595  if(mRunNumber < 6000000)mapp=mPmdGeom->ChainMapping(Chain_No,channel,supmod,col,row,chtemp); // 2004 data
596  if(mRunNumber >= 6000000)mapp=mPmdGeom->ChainMapping(Chain_No,channel,supmod,col,row,chtemp,year); // 2005 onwards data
597  Int_t DaqADC=adc[AddCh_Count];
598  // zeroing zeroeth channel
599  if(channel==0)DaqADC=0;
600 
601  AddCh_Count++;
602 
603  if(DaqADC>0 && mapp==kStOK){
604  orig_nhits++;
605  //Fill chain-channel QA
606  m_chain_channel->Fill(channel,Chain_No-1);
607 
608  // Apply uniformity calibration here
609  //
610  Float_t cellgain = 1;
611  Float_t smchaingain = 1;
612  Float_t cellstatus = 1;
613  //fout<<" "<<mRunNumber<<" "<<supmod<<" "<<row<<" "<<col<<" "<<DaqADC<<endl;
614  //cout<<" "<<mRunNumber<<" "<<supmod<<" "<<row<<" "<<col<<" "<<DaqADC<<endl;
615  if(mCalibFlag){
616  Float_t calib = 1;
617  Float_t final_factor = 0;
618 
619  if(supmod<=(2*PMD_CRAMS_MAX) && row <=PMD_ROW_MAX && col <=PMD_COL_MAX){
620 
621  Int_t stCalib = GetCalib(supmod,row,col,calib);
622  if(stCalib != kStOK)gMessMgr->Info("Problem in getting Calibration Constant");
623 
624  if(mRunNumber < 8000000){
625  // final_factor=calib;
626  final_factor=1.;
627  }
628  if(mRunNumber >= 8000000){
629  //storing gain factors for StPmdHit to be used in ClusterMaker
630  cellgain=calib;
631  smchaingain=SM_chain_factor[supmod-1][Chain_No-1];
632  // application of finalfactor
633  final_factor=calib*SM_chain_factor[supmod-1][Chain_No-1];
634  // fout<<"ADC, chain, row, col, calib, sm_chain "<<DaqADC<<" "<<Chain_No<<" "<<row<<" "<<col<<" "<<calib<<" "<<SM_chain_factor[supmod-1][Chain_No-1]<<" final_factor="<<final_factor<<endl;
635  if(!Accept(Chain_No,channel)){
636  final_factor=0.0;
637  cellstatus=0;
638  }
639  // if(SubDet==1) fout<<supmod-1<<" "<<col-1<<" "<<row-1<<" "<<calib<<" "<<smchaingain<<" "<<cellstatus<<endl;
640  }
641  //if(calib!=0)DaqADC=(Int_t)(DaqADC*calib);
642  //
643  // cout<<supmod<<","<<row<<","<<col<<","<<Chain_No<<","<<calib<<","<<SM_chain_factor[supmod-1][Chain_No-1]<<","<<final_factor<<","<<DaqADC<<endl;;
644  if(final_factor>0){
645  //subhasi: stop applying gain factor here, apply in clusterMaker
646  // DaqADC=(Int_t)(1.0*DaqADC/final_factor);
647  }else{
648  // DaqADC=0;
649  }
650 
651 
652  } //Check on overflow of supmod, row col
653  } // Calibration flag
654 
655  // Converting ADC to Edep
656  Float_t edep=0;
657  // mPmdGeom-> ADC2Edep(DaqADC, edep);
658  // The old edep was a function of ADC itself available in StPmdGeom.
659  // cell_status = 0 for cells for which calibration is not available
660  // cell_status = 1 for cells for which calibration is available
661  // final factor is the cellGNF*SMChainGNF for all cleaned cells
662  // cout<<"DaqADC="<<DaqADC<<" cellgain = "<<cellgain<<" smchaingain = "<<smchaingain<<" cellstatus="<<cellstatus<<endl;
663  edep = DaqADC *cellstatus/(cellgain*smchaingain);
664  if(edep<0) edep=0;
665 
666  if(DaqADC>0){
667  // cout<<"sm, row, col,adc, edep "<<supmod<<","<<row<<","<<col<<","<<DaqADC<<" "<<edep<<endl;;
668  //Fill StPmdHit
669  StPmdHit *pmdhit = new StPmdHit();
670  nhits_sm[supmod-1]++;
671  if(supmod>PMD_CRAMS_MAX)supmod-=PMD_CRAMS_MAX;
672  pmdhit->setGsuper(Int_t(supmod));
673  pmdhit->setSubDetector(Int_t(SubDet));
674  pmdhit->setRow(Int_t(row));
675  pmdhit->setColumn(Int_t(col));
676  pmdhit->setAdc(Int_t(DaqADC));
677  pmdhit->setEdep(Float_t(edep));
678  // gain related
679  pmdhit->setGainCell(Float_t(cellgain));
680  pmdhit->setGainSmChain(Float_t(smchaingain));
681  pmdhit->setCellStatus(Float_t(cellstatus));
682 
683  if(SubDet==2)det0->addHit(pmdhit);
684  if(SubDet==1)det1->addHit(pmdhit);
685  nhits++;
686  } // Check on non zero DaqADC after calibration and Accept()
687 
688  } //Check on non zero DaqADC
689 
690  } //CHANNEL
691  } //BLOCK
692  } //C-RAM
693  } //SEC
694 
695  if(Debug()){
696  cout<<" NUmber of channels read ="<<AddCh_Count<<endl;
697  cout<<" NUmber of original hits ="<<orig_nhits<<endl;
698  cout<<" number of hits="<<nhits<<endl;
699  for(Int_t ism = 0;ism<24;ism++){
700  if(nhits_sm[ism]>0) cout<<"number of hits in module "<<ism+1<<" is ="<<nhits_sm[ism]<<endl;
701  }
702  }
703  if(mPmdPrint)gMessMgr->Info("StEvent to be called **");
704  Int_t testevt=fillStEvent(det0,det1); //called as (cpv_det,pmd_det)
705  if(testevt!=kStOK){
706  gMessMgr->Info("Problem in fillStEvent");
707  return kStWarn;
708  }
709 //
710  return kStOK;
711 }
712 //-------------------------------------------------------------------------
713 
714 Int_t StPmdReadMaker::fillStEvent(StPmdDetector* cpv_det, StPmdDetector* pmd_det){
715  // Look for StEvent
716  StEvent *currevent = (StEvent*)GetInputDS("StEvent");
717  //
718  if(!currevent){
719  gMessMgr->Info("NO STEVENT**");
720  // StEvent *currevent=new StEvent();
721 
722  return kStWarn;
723  }
724 // Int_t ctbm=currevent->triggerData()->ctbSum(0);
725 // Int_t tofm=currevent->triggerData()->tofMultiplicity(0);
726  // Create PhmdCollection, first Maker in Chain, so here it is created
727  mEvtPmdCollection = new StPhmdCollection();
728  currevent->setPhmdCollection(mEvtPmdCollection);
729 
730  //Set the Detectors to PhmdCollection
731  if(mEvtPmdCollection){
732  mPmdEvent = mEvtPmdCollection->detector(StDetectorId(kPhmdId));
733  mCpvEvent = mEvtPmdCollection->detector(StDetectorId(kPhmdCpvId));
734  }
735  Int_t tothit_pmd=0;
736  Int_t tothit_cpv=0;
737 
738  // StEventInfo* eventInfo = currevent->info();
739  // Int_t Nevent=eventInfo->id();
740 
741  // if(!mEvtPmdCollection){
742  // cout<<"No PMDCOLLECTION **, Creating one"<<endl;
743  // mEvtPmdCollection = new StPhmdCollection();
744  // currevent->setPhmdCollection(mEvtPmdCollection);
745  // mPmdEvent = mEvtPmdCollection->detector(StDetectorId(kPhmdId));
746  // mCpvEvent = mEvtPmdCollection->detector(StDetectorId(kPhmdCpvId));
747  //}
748 
749  for(Int_t id=1;id<(PMD_CRAMS_MAX+1);id++){
750 
751  //Fill StEvent info for PMD and CPV, first PMD(subdet=1)
752  //does the id goes from 1 to 12 for PmdHit (for PhmdHit it goes 0-11).
753 
754  StPmdModule * pmd_mod=pmd_det->module(id);
755  Int_t nmh1=pmd_det->module_hit(id);
756 
757  if(nmh1>0){
758  // cout<<" PMD: Filled "<<nmh1<<" hits in Pre"<<endl;
759  TIter next(pmd_mod->Hits());
760  StPmdHit *spmcl1;
761  for(Int_t im=0; im<nmh1; im++)
762  {
763  spmcl1 = (StPmdHit*)next();
764  if(spmcl1){
765  Int_t subdet=spmcl1->SubDetector();
766  Int_t gsuper=spmcl1->Gsuper();
767  Int_t col=spmcl1->Column();
768  Int_t row=spmcl1->Row();
769  Float_t edep=spmcl1->Edep();
770  Int_t adc=spmcl1->Adc();
771 
773 
774  StPhmdHit *phit = new StPhmdHit();
775  /*
776  phit->setSuperModule(Int_t(gsuper-1)); // filling supermodule no (range 0-11)
777  phit->setSubDetector(Int_t(subdet)); // filling subdetector
778  phit->setRow(Int_t(row)); // filling row
779  phit->setColumn(Int_t(col)); // filling col
780  phit->setEnergy(edep); // filling energy
781  phit->setAdc(adc); // filling ADC
782  */
783  // changed to accommodate numbering scheme (i.e start from 0)
784  phit->setSuperModule(Int_t(gsuper-1)); // filling supermodule no (range 0-11)
785  phit->setSubDetector(Int_t(subdet-1)); // filling subdetector (pmd=0,cpv=1)
786  phit->setRow(Int_t(row-1)); // filling row (starts from 0)
787  phit->setColumn(Int_t(col-1)); // filling col (starts from 0)
788  phit->setEnergy(edep); // filling energy
789  phit->setAdc(adc); // filling ADC
790  tothit_pmd++;
791  if(mPmdEvent)mPmdEvent->addHit(phit);
792  }
793  }
794  }
795 
796  //Now CPV (subdet=2) //////
797 
798  Int_t nmh2=cpv_det->module_hit(id);
799  StPmdModule * cpv_mod=cpv_det->module(id);
800 
801  if(nmh2>0)
802  {
803  cout<<" PMD: Filled "<<nmh2<<" hits in CPV"<<endl;
804  TIter next(cpv_mod->Hits());
805  StPmdHit *spmcl2;
806  for(Int_t im=0; im<nmh2; im++)
807  {
808  spmcl2 = (StPmdHit*)next();
809  if(spmcl2){
810  Int_t subdet=spmcl2->SubDetector();
811  Int_t gsuper=spmcl2->Gsuper();
812  Int_t col=spmcl2->Column();
813  Int_t row=spmcl2->Row();
814  Float_t edep=spmcl2->Edep();
815  Int_t adc=spmcl2->Adc();
816 
817  StPhmdHit *phit = new StPhmdHit();
818 
819  // changed to accommodate numbering scheme (i.e start from 0)
820  phit->setSuperModule(Int_t(gsuper-1)); // filling supermodule no (range 0-11)
821  phit->setSubDetector(Int_t(subdet-1)); // filling subdetector (pmd=0,cpv=1)
822  phit->setRow(Int_t(row-1)); // filling row (starts from 0)
823  phit->setColumn(Int_t(col-1)); // filling col (starts from 0)
824  phit->setEnergy(edep); // filling energy
825  phit->setAdc(adc); // filling ADC
826 
827  tothit_cpv++;
828  if(mCpvEvent)mCpvEvent->addHit(phit);
829  }
830  }
831  }
832  }
833  // m_event_tothit_pmd->Fill(Nevent,tothit_pmd);
834  // m_event_tothit_cpv->Fill(Nevent,tothit_cpv);
835 
836  return kStOK;
837 }
838 
839 //------------------------------------------------------------------
840 
841 Int_t StPmdReadMaker::Finish() {
842  if(mPmdPrint)gMessMgr->Info("StPmdReadMaker::Finish()");
843  TFile * f = new TFile("11030019run_2010_histo_QA.root", "RECREATE");
844  for(Int_t nchain=0; nchain<49; nchain++)
845  {
846  chain_mean[nchain]->Write();
847  chain_rms[nchain]->Write();
848  chain_adc[nchain]->Write();
849  }
850  pmdhit_tof->Write();
851  pmdadc_tof->Write();
852  f->Close();
853  return StMaker::Finish();
854 }
855 
856 //------------------------------------------------------------------
857 
858 void StPmdReadMaker::bookHist(){
859  //m_event_tothit_pmd = new TH1F("pmd_tothit","tothit vs eventNo (PMD)",10000,0,100000);
860  //m_event_tothit_cpv = new TH1F("cpv_tothit","tothit vs eventNo (CPV)",10000,0,100000);
861  pmdhit_tof = new TH2F("pmdhit_tof","",1000,0,100000, 1000, 0, 10000);
862  pmdadc_tof = new TH2F("pmdadc_tof","",1000,0,100000, 1000, 0, 10000);
863 
864  m_chain_channel = new TH2F("chain_chan","channel vs chain No ",1728,-0.5,1727.5,48,-0.5,47.5);
865  for (Int_t chain1 =0;chain1<49;chain1++)
866  {
867  Char_t text[20],title[20];
868  sprintf(text,"chain_rms%02d",chain1);
869  sprintf(title,"chain_rms%02d",chain1);
870  chain_rms[chain1] = new TH1D(text,title,1730,0,1730);
871  sprintf(text,"chain_mean%02d",chain1);
872  sprintf(title,"chain_mean%02d",chain1);
873  chain_mean[chain1] = new TH1D(text,title,1730,0,1730);
874  Char_t text1[20],title1[20];
875  sprintf(text1,"chain_adc%02d",chain1);
876  sprintf(title1,"chain_adc%02d",chain1);
877  chain_adc[chain1] = new TH1D(text1,title1,1730,0,1730);
878  }
879 }
880 
881 //---------------------------------------------------------------------
882 Bool_t StPmdReadMaker::IsHot(Int_t chain,Int_t channel){
883  // Find out if a given chain/channel is "hot"
884  // DB stores element IDs 1-48 => table rows 0-47 => chains 1-48
885  // DB stores 1728 channels as 54 x 32bit words (1-1728)
886  if (!mHotCells) return kFALSE;
887 
888  // channel--;
889  Int_t offset = channel/32;
890  Int_t bit = channel%32;
891 
892  pmdHotCells_st* chainCells = mHotCells->GetTable(chain-1);
893  unsigned int* bitMask = &(chainCells->m00);
894  bitMask += offset;
895  Bool_t isHot = ( ((*bitMask) & (((unsigned int) 1) << (31-bit))) != 0 );
896  // static int isHotCount = 0;
897  if (isHot) {
898  // isHotCount++;
899  // cout<<" isHot: "<< isHotCount << endl;
900  // mHotTracks++;
901  // if(Debug())cout<<"chain/channel="<<chain<<" "<<channel<<endl;
902  // cout<<"in IsHOT: chain/channel="<<chain<<" "<<channel<<endl;
903  }
904  // temporarily put here by RR
905  // to remove chain 11 and chain 13
906  // if (chain==11|| chain==13) isHot=kTRUE;
907  return isHot;
908 }
909 
910 //----------------------------------------------------------
911 
912 Bool_t StPmdReadMaker::Accept(Int_t chain,Int_t channel){
913 
914  if (channel==0)return kFALSE;
915  // This should have access to database of hot channels according to year
916 
917  for(Int_t i=0;i<25;i++){
918  // if the chain is not to be included in the analysis for some reason
919  if (chain==BadChain[i]){
920  // fout<<"BadChain="<<BadChain[i]<<endl;
921  return kFALSE;
922  }
923  }
924  // Int_t chain_channel = chain*1728+channel;
925  // return !IsHot(chain_channel);
926  return !IsHot(chain,channel);
927 
928 }
929 
930 //----------------------------------------------------------------------
931 
932 Bool_t StPmdReadMaker::ReadCalibrationsConst(){
933 
934  if(Debug()) cout<<" StPmdReadMaker::I AM IN READCALIB "<<endl;
935 
937  StDbConfigNode* node=mgr->initConfig("Calibrations_pmd");
938  node->setVersion("SMChain");
939 
940  mDb=NULL;
941  m_PmdCalibConst=NULL;
942  TString DbName = "Calibrations/pmd";
943  mDb=GetInputDB(DbName.Data());
944  if(Debug())cout<<"after mDB"<<endl;
945  if(!mDb) return kFALSE;
946  // fout<<"after !mDb"<<mDb->GetTimeStamp()<<endl;
947 
948  for(Int_t ism=0;ism<24;ism++){
949  for(Int_t chain=0;chain<48;chain++){
950  SM_chain_factor[ism][chain]=0.;
951  }
952  }
953  //getting tables ////////////////////////////////////////////////////
954 
955  // Cell_GNF Tables
956  pmdCalSummary_st* pmdcalsum = NULL;
957  St_pmdCalSummary* summ = (St_pmdCalSummary*) mDb->Find("pmdCalSummary");
958  if(summ) pmdcalsum = summ->GetTable();
959 
960  pmdSMCalib_st* pmdcalibst = NULL;
961  TString TableName;
962  St_pmdSMCalib* a = (St_pmdSMCalib*) mDb->Find("pmdSMCalib");
963  if(a) pmdcalibst = a->GetTable();
964  if(!pmdcalibst) return kFALSE;
965  m_PmdCalibConst=pmdcalibst;
966  if(Debug())cout<<"obtained the Cell_GNF Tables"<<endl;
967 
968  // HOT CELLS
969  mHotCells = (St_pmdHotCells*) mDb->Find("pmdHotCells");
970  if (!mHotCells) {
971  gMessMgr->Warning("pmdHotCells not found!");
972  return kFALSE;
973  }
974  Int_t nhot = 0;
975  for (Int_t chain=1; chain <= 48; chain++) {
976  pmdHotCells_st* chainCells = mHotCells->GetTable(chain-1);
977  if (!chainCells) {
978  cout<<"End-of-DbTable. Stopping."<<endl;
979  return kFALSE;
980  }
981 
982  for (Int_t offset=0; offset<54; offset++) {
983  unsigned int* bitMask = &(chainCells->m00);
984  bitMask += offset;
985  // if (*bitMask!=0)cout<<chain<<" "<<offset<<" "<<*bitMask<<endl;
986  for (Int_t bit=31; bit>=0; bit--) {
987  if ( ((*bitMask) & (((unsigned int) 1) << bit)) != 0 ) {
988  // Int_t channel = offset*32 + (31-bit);
989  // printf("%2d %4d",chain,channel);
990  // fout<<bit<<" "<<chain<<" "<<channel<<endl;
991  nhot++;
992  }
993  }
994  }
995 
996  }
997  if(Debug()) cout<<" number of hot cells is "<< nhot<<endl;
998  //cout<<"PMD: number of hot cells is "<< nhot<<endl;
999 
1000  // SM_CHAIN_GNF
1001 
1002  St_pmdSMChain_GNF * tab = (St_pmdSMChain_GNF*) mDb->Find("pmdSMChain_GNF");
1003  if (!tab) {
1004  cout<<"No pmdSMChain_GNF DBTable. Stopping."<<endl;
1005  return kFALSE;
1006  }
1007 
1008  // cout<<"Got SmChain tables"<<endl;
1009  // int sm,chain;
1010  // float meancor,meancor_err,mpvcor,mpvcor_err;
1011 
1012  // fout<<"Reading SMChain_GNF "<<endl;
1013 
1014  for (Int_t ismchain=0; ismchain<64; ismchain++) {
1015  pmdSMChain_GNF_st* smchain = tab->GetTable(ismchain);
1016  if (!smchain) {
1017  cout<<"End-of-SmChain DbTable. Stopping."<<endl;
1018  return kFALSE;
1019  }
1020  // Range of SM, Chain: from 0 or 1
1021  long supmod = smchain->sm;
1022  long chainNo=smchain->chain;
1023  float MeanFactor = smchain->mean_factor;
1024  float MPVFactor = smchain->mpv_factor;
1025  // SM_chain_factor[supmod-1][chainNo-1]=MPVFactor;
1026  SM_chain_factor[supmod-1][chainNo-1]=MeanFactor;
1027 
1028  //struct pmdSMChain_GNF {
1029  // long sm; /* super module */
1030  // long chain; /* chain */
1031  // float mean_factor; /* mean */
1032  // float errmean_factor; /* error on mean */
1033  // float mpv_factor; /* most probable value */
1034  // float errmpv_factor; /* error on mpv */
1035  //};
1036  if(Debug()){
1037  if(supmod>0 && chainNo>0){
1038  cout<<"SM,Chain,mean_factor,mpv_factor "<<supmod<<" "<<chainNo<<" "<<MeanFactor<<" "<<MPVFactor<<" "<<SM_chain_factor[supmod-1][chainNo-1]<<endl;
1039  }
1040  }
1041  }
1042  return kTRUE;
1043 
1044 }
1045 
1046 //------------------------------------------------------------------
1047 
1048 Int_t StPmdReadMaker::GetCalib(int sm,int row,int col,float& calib)
1049 {
1050  if(sm>0 && row>0 && col>0)
1051  if(m_PmdCalibConst)calib=m_PmdCalibConst[sm-1].CellGain[row-1][col-1];
1052 
1053  // cout<<"sm,row,col,calib"<<sm<<" "<<row<<" "<<col<<" "<<calib<<endl;
1054  // if(Debug() && calib>0)fout<<"sm,row,col,calib "<<sm<<" "<<row<<" "<<col<<" "<<calib<<endl;
1055  return kStOK;
1056 
1057 }
1058 
1059 //------------------------------------------------------------------------------
bool addHit(StPmdHit *)
no of modules
Int_t module_hit(Int_t)
module number
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
void setGsuper(Int_t)
Cell status (chain selection based)
Definition: StPmdHit.h:104
Definition: Stypes.h:42
Definition: Stypes.h:40
Definition: daq_pmd.h:7
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
virtual Int_t Finish()
Definition: StMaker.cxx:776
StPmdModule * module(unsigned int)
number of hits
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362