StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcRawMapMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StEEmcRawMapMaker.cxx,v 1.3 2012/05/09 21:11:58 sgliske Exp $
4  * Author: S. Gliske, April 2012
5  *
6  ***************************************************************************
7  *
8  * Description: see header.
9  *
10  ***************************************************************************
11  *
12  * $Log: StEEmcRawMapMaker.cxx,v $
13  * Revision 1.3 2012/05/09 21:11:58 sgliske
14  * updates
15  *
16  * Revision 1.2 2012/04/13 15:08:43 sgliske
17  * updates
18  *
19  * Revision 1.1 2012/04/12 17:11:16 sgliske
20  * creation
21  *
22  *
23  **************************************************************************/
24 
25 #include <map>
26 
27 #include "StMaker.h"
28 #include "StEEmcRawMapMaker.h"
29 
30 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
31 #include "StMuDSTMaker/COMMON/StMuDst.h"
32 
33 #include "StEEmcUtil/database/StEEmcDb.h"
34 #include "StEEmcUtil/database/EEmcDbItem.h"
35 #include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h"
36 
37 #include "StEvent/StEvent.h"
38 #include "StEvent/StEmcDetector.h"
39 #include "StEvent/StEmcModule.h"
40 #include "StEvent/StEmcRawHit.h"
41 #include "StEvent/StEmcCollection.h"
42 
43 #include "StMessMgr.h"
44 
45 #define TRIG
46 //#define DEBUG
47 
48 #ifdef TRIG
49 #include "StMuDSTMaker/COMMON/StMuEvent.h"
50 #include "StEvent/StTriggerIdCollection.h"
51 #include "StEvent/StTriggerId.h"
52 #endif
53 
54 // constructors
55 StEEmcRawMapMaker::StEEmcRawMapMaker( const Char_t* name ) : StMaker( name ), mInputType(-1), mInputName(""), mEEmcDb(0) { /* */ };
56 
57 // deconstructor
58 StEEmcRawMapMaker::~StEEmcRawMapMaker(){ /* */ };
59 
60 Int_t StEEmcRawMapMaker::setInput( const Char_t *name, Int_t type ){
61  Int_t ierr = kStOk;
62 
63  if( type == 0 || type == 1){
64  mInputType = type;
65  mInputName = name;
66  } else {
67  LOG_ERROR << "Invalid input type" << endm;
68  ierr = kStFatal;
69  };
70  return ierr;
71 };
72 
73 Int_t StEEmcRawMapMaker::Init(){
74  Int_t ierr = kStOk;
75 
76  if( mInputType != 0 && mInputType != 1){
77  LOG_ERROR << "Input mInputType not set to valid value" << endm;
78  ierr = kStFatal;
79  };
80 
81  return ierr;
82 };
83 
86 
87  Int_t ierr = kStOk;
88 
89  mEEmcDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
90  if( !mEEmcDb ){
91  LOG_ERROR << "Error finding EEMC DB" << endm;
92  this->ls();
93  ierr = kStFatal;
94  };
95 
96  if( !ierr ){
97  if( mInputType ){
98  ierr = loadFromMuDst();
99  } else {
100  ierr = loadFromStEvent();
101  };
102  };
103 
104  return ierr;
105 };
106 
108  Int_t ierr = kStOk;
109 
110  const StMuDst* muDst = (const StMuDst*)GetInputDS( mInputName.data() );
111  const StMuEmcCollection* emc = 0;
112  if( muDst )
113  emc = muDst->muEmcCollection();
114 
115  if( !emc ){
116  ierr = kStFatal;
117  LOG_ERROR << "Error finding MuEmc Collection from MuDst" << endm;
118  };
119 
120  if( !ierr ){
121 
122 #ifdef DEBUG2
123  LOG_INFO << "Number of towers in MuDst " << emc->getNEndcapTowerADC() << endm;
124 #endif
125 
127  for ( Int_t i = 0; i < emc->getNEndcapTowerADC(); ++i ){
128  Int_t adc, sec, sub, eta;
129  emc->getEndcapTowerADC( i, adc, sec, sub, eta );
130 
131  // need to switch from indexing from 1 to indexing from 0
132  sec--;
133  sub--;
134  eta--;
135 
136  if( (sec >= 0) && (sec < kEEmcNumSectors ) && (sub >= 0) && (sub < kEEmcNumSubSectors ) && (eta >= 0) && (eta < kEEmcNumEtas) )
137  addHitTower(sec,sub,eta,adc,0);
138  };
139 
141  for ( Int_t i = 0; i < emc->getNEndcapPrsHits(); i++ ){
142 
143  Int_t adc, sec, sub, eta, det;
144  const StMuEmcHit *hit = emc->getEndcapPrsHit(i, sec, sub, eta, det);
145  if ( hit ){
146  adc = hit -> getAdc();
147 
148  // need to switch from indexing from 1 to indexing from 0
149  sec--;
150  sub--;
151  eta--;
152 
153  if( (sec >= 0) && (sec < kEEmcNumSectors ) && (sub >= 0) && (sub < kEEmcNumSubSectors ) && (eta >= 0) && (eta < kEEmcNumEtas) )
154  addHitTower(sec,sub,eta,adc,det);
155 
156  };
157  };
158  };
159 
160  //
161  // LOAD SMD DATA
162  //
163  if( !ierr ){
164  Char_t cpl[] = { 'U','V' };
165  for ( Int_t plane = 0; plane < 2; plane++ ){
166  for ( Int_t ihit = 0; ihit < emc->getNEndcapSmdHits(cpl[plane]); ihit++ ) {
167  Int_t sec, strip, adc;
168  const StMuEmcHit *hit = emc->getEndcapSmdHit( cpl[plane], ihit, sec, strip );
169  adc = hit->getAdc();
170 
171  sec--; // adjust indexing
172  strip--; //
173 
174  if ((sec >= 0) && (sec < 12) && (strip >= 0) && (strip < 288))
175  addHitStrip(sec,plane,strip,adc);
176  };
177  };
178  };
179 
180 
181 #ifdef TRIG
182  StMuEvent *event = muDst->event();
183  if( event ){
184  const StTriggerId& l1trig = event->triggerIdCollection().l1();
185  cout << "Passed trigger? " << l1trig.isTrigger( 380301 ) << ' ' << l1trig.isTrigger( 380302 ) << endl;
186  };
187 #endif
188 
189 #ifdef DEBUG
190  LOG_INFO << "Number of towers in MuDst " << emc->getNEndcapTowerADC() << " vs in raw Map " << mMap[0].size() << endm;
191 #endif
192 
193  return ierr;
194 };
195 
197  Int_t ierr = kStOk;
198 
199  const StEvent *event = (const StEvent*)GetInputDS( mInputName.data() );
200  const StEmcCollection *emc = 0;
201 
202  if( event )
203  emc = event->emcCollection();
204 
205  if( !emc ){
206  LOG_ERROR << "Error reading from StEvent" << endm;
207  ierr = kStFatal;
208  };
209 
210  const StEmcDetector *detector = 0;
211  StDetectorId detectorIds[] = { kEndcapEmcTowerId, kEndcapEmcPreShowerId };
212 
213  //
214  // TOWERS, PRESHOWERS and POSTSHOWER
215  //
216 
217  if( !ierr ){
218  for( Int_t iDet = 0; iDet < 2; ++iDet ){
219  detector = emc->detector( detectorIds[iDet] );
220 
221  if ( !detector ){
222  LOG_ERROR << "Error finding EEMC detector in EEmc collection" << endm;
223  ierr = kStFatal;
224  } else {
225  // loop over towers
226  for ( UInt_t sec = 0; sec < detector->numberOfModules(); sec++ ){
227 
230  const StEmcModule *sector = detector->module( sec+1 );
231  if( sector ){
232  const StSPtrVecEmcRawHit &hits = sector->hits();
233 
235  for ( UInt_t ihit=0; ihit<hits.size(); ihit++ ){
236  if (!hits[ihit]) {
237 
239  Int_t sec = hits[ihit]->module() - 1;
240  Int_t sub = hits[ihit]->sub() - 1;
241  Int_t eta = hits[ihit]->eta() - 1;
242  Int_t adc = hits[ihit]->adc();
243 
244  Int_t layer = (hits[ihit]->sub() - 1) / 5 + 1;
245  if( (layer >= 0) && (layer < 4) && (sec >= 0) && (sec < kEEmcNumSectors) && (sub >= 0) && (sub < kEEmcNumSubSectors ) && (eta >= 0) && (eta < kEEmcNumEtas) )
246  addHitTower(sec,sub,eta,adc,layer);
247  };
248  };
249  };
250  };
251  };
252  };
253  };
254 
255  //
256  // SMD STRIPS
257  //
258 
259  if( !ierr ){
260  StDetectorId ids[] = { kEndcapSmdUStripId, kEndcapSmdVStripId };
262  for( Int_t iplane=0; iplane<2; iplane++ ){
263 
265  detector=emc->detector( ids[iplane] );
266  assert( detector );
267 
268  for( UInt_t sec = 0; sec<detector->numberOfModules(); sec++ ){
271  const StEmcModule *sector = detector->module( sec+1 );
272  const StSPtrVecEmcRawHit &hits = sector->hits();
273 
275  for ( UInt_t ihit=0; ihit<hits.size(); ihit++ ){
276  Int_t isector = hits[ihit]->module()-1;
277  Int_t istrip = hits[ihit]->eta()-1;
278  Int_t adc = hits[ihit]->adc();
279  if( (isector >= 0) && (isector < 12) && (istrip >= 0) && (istrip < 288) )
280  addHitStrip( isector, iplane, istrip, adc);
281  };
282  };
283  };
284  };
285 
286  return ierr;
287 };
288 
289 void StEEmcRawMapMaker::addHitTower( Int_t sec, Int_t sub, Int_t eta, Int_t adc, Int_t layer ){
290 
291  Int_t index = eta + kEEmcNumEtas*( sub + kEEmcNumSubSectors*sec );
292 
293 // #ifdef DEBUG2
294 // if( GetEventNumber() == 868734 && index == 336 ){
295 // LOG_INFO << "Event " << GetEventNumber() << " adding tower " << index << ' ' << layer << ' ' << adc << endm;
296 // };
297 // #endif
298 
299  StEEmcRawMapData& data = mMap[layer][index];
300  data.rawAdc = adc;
301 
302  assert( mEEmcDb );
303  static const Char_t subsectors[] = { 'A','B','C','D','E' };
304  static const Char_t detectors[] = { 'T', 'P', 'Q', 'R' };
305  const EEmcDbItem *dbitem = mEEmcDb->getTile( sec+1,subsectors[sub],eta+1, detectors[layer] );
306  assert( dbitem );
307 
308  data.fail = dbitem->fail;
309  data.stat = dbitem->stat;
310  data.ped = dbitem->ped;
311  data.pedSigma = dbitem->sigPed;
312  data.gain = dbitem->gain;
313 };
314 
315 void StEEmcRawMapMaker::addHitStrip( Int_t sec, Bool_t layerIsV, Int_t strip, Int_t adc ){
316 
317  Int_t index = strip + kEEmcNumStrips*( layerIsV + kEEmcNumSmdUVs*sec );
318 
319  StEEmcRawMapData& data = mMap[ESMD][index];
320  data.rawAdc = adc;
321 
322  assert( mEEmcDb );
323  const EEmcDbItem *dbitem = mEEmcDb->getByStrip ( sec+1, (layerIsV ? 'V' : 'U'), strip+1 );
324  assert( dbitem );
325 
326  data.fail = dbitem->fail;
327  data.stat = dbitem->stat;
328  data.ped = dbitem->ped;
329  data.pedSigma = dbitem->sigPed;
330  data.gain = dbitem->gain;
331 };
332 
333 void StEEmcRawMapMaker::Clear( Option_t *opt ){
334  mMap[0].clear();
335  mMap[1].clear();
336  mMap[2].clear();
337  mMap[3].clear();
338 };
339 
340 ClassImp(StEEmcRawMapMaker);
virtual void Clear(Option_t *opt="")
User defined functions.
int getAdc() const
Return ADC value.
Definition: StMuEmcHit.h:19
virtual Int_t Make()
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
Definition: StMuDst.h:389
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Definition: Stypes.h:41