StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcFastMaker.cxx
1 // *-- Author : J.Balewski, A.Ogawa, P.Zolnierczuk
2 //
3 // $Id: StEEmcFastMaker.cxx,v 1.23 2010/08/05 21:23:45 stevens4 Exp $
4 
5 #include "St_DataSetIter.h"
6 #include "StEventTypes.h"
7 
8 #include "StEEmcFastMaker.h"
9 
10 
11 #include "StEEmcUtil/EEevent/EEeventDst.h"
12 #include "StEEmcUtil/EEevent/EEsectorDst.h"
13 #include "StEEmcUtil/EEevent/EEtwHitDst.h"
14 #include "StEEmcUtil/EEevent/EEsmdHitDst.h"
15 
16 #include "StEEmcUtil/EEmcMC/EEmcMCData.h"
17 #include "StEEmcUtil/EEmcGeom/EEmcGeomDefs.h"
18 
19 
20 ClassImp(StEEmcFastMaker)
21 
22 //--------------------------------------------
23 void
24 StEEmcFastMaker::Clear(Option_t *) {
25  meeve->Clear();
26  if(mEmcCollectionIsLocal) { // special use
27  delete mLocalStEmcCollection;
28  mLocalStEmcCollection=0;
29  }
30 
32 }
33 
34 //--------------------------------------------
35 StEEmcFastMaker::StEEmcFastMaker(const char *name):StMaker(name){
37  SetEmcCollectionLocal(false);
38  mLocalStEmcCollection=0;
39  mUseFullTower = true; // default value for BFC, for consumption by the EEMC slow simulator
40  mUseFullPreShower = false;
41  mUseFullSmdu = false;
42  mUseFullSmdv = false;
43  mevIN= new EEmcMCData;
44  meeve= new EEeventDst;
45 
46 
47  mfixTgain=new float [kEEmcNumEtas];
48  for (Int_t i=0;i<kEEmcNumEtas;i++) {
49  mfixTgain[i]=getTowerGains()[i];
50  }
51 
52 
53 
54 }
55 
56 //--------------------------------------------
57 StEEmcFastMaker::~StEEmcFastMaker(){
58  delete mevIN;
59  delete meeve;
60  delete [] mfixTgain;
61  if(mEmcCollectionIsLocal){
62  mLocalStEmcCollection->Clear();
63  delete mLocalStEmcCollection;
64  }
65 }
66 
67 //--------------------------------------------
68 //--------------------------------------------
69 //--------------------------------------------
70 Int_t
71 StEEmcFastMaker::Init(){
72  LOG_INFO<<"::Init() \n"<< endm;
73  if(mEmcCollectionIsLocal) { // special use
74  LOG_INFO<<"::Init() use local EmcCollection\n"<< endm;
75  }
76  return StMaker::Init();
77 }
78 
79 //--------------------------------------------
80 //--------------------------------------------
81 //--------------------------------------------
82 Int_t
84 
85  LOG_INFO <<"::Make() , mEmcCollectionIsLocal="<<mEmcCollectionIsLocal<<endm;
86  meeve->clear();
87 
88  int nh=-1;
89  if ( (nh = mevIN->readEventFromChain(this)) >0) {
90  LOG_INFO <<" RAW geant EEMC hits="<<nh<<endm;
91  //tmp if(Debug())mevIN->print();
92  } else {
93  LOG_INFO <<" RAW geant EEMC not seen"<<endm;
94  return kStOK;
95  }
96 
97  EEeventDst eeveRaw; // raw M-C hits
98 
99  // generation of TTree
100  mevIN->write(&eeveRaw); // Clear & Store RAW EEevent
101  //tmp LOG_DEBUG<< Form(":: raw eeveRaw.print():\n",GetName());eeveRaw.print();}
102 
103  eeveRaw.sumRawMC(meeve); //sum hits with any detector
104  //tmp if(Debug()){ printf("%s:: summed eeve.print():\n",GetName());meeve->print();}
105 
106  StEmcCollection *emcColl=0;
107  if(mEmcCollectionIsLocal) { // special use
108  mLocalStEmcCollection=new StEmcCollection();
109  emcColl=mLocalStEmcCollection;
110  } else { // standard action
111  StEvent *stevent = (StEvent *) GetInputDS("StEvent");
112  assert(stevent); // do sth to provide StEvent first
113  emcColl=stevent->emcCollection();
114  if(emcColl==0) {
115  emcColl=new StEmcCollection();
116  stevent->setEmcCollection(emcColl);
117  LOG_WARN<<"::Make() has added a non existing StEmcCollection()"<<endm;
118  }
119  }
120 
121  mEE2ST(meeve, emcColl);
122 
123  return kStOK;
124 }
125 
126 
127 //--------------------------------------------
128 //--------------------------------------------
129 //--------------------------------------------
130 void
131 StEEmcFastMaker::mEE2ST(EEeventDst* eevt, StEmcCollection* emcC){
132  int mxSector = kEEmcNumSectors;
133 
134  //tmp eevt->print();
135  assert(emcC);
136  LOG_DEBUG<< Form("EE2ST got emcCollection\n")<<endm;
137 
138  for(int det = kEndcapEmcTowerId; det<= kEndcapSmdVStripId; det++){
139 
140  StDetectorId id = StDetectorId(det);
141  StEmcDetector* d = new StEmcDetector(id,mxSector);
142  emcC->setDetector(d);
143  TClonesArray* tca;
144  LOG_DEBUG<< Form("EE2ST() copy hits from %d EEMC sectors, det=%d\n",eevt->getNSectors(),det)<<endm;
145 
146  for(int isec=0; isec<mxSector; isec++){ // over used sectors
147  int secID=isec+1;
148  EEsectorDst* EEsec = (EEsectorDst*)eevt->getSec(secID);
149  //if(EEsec==0) continue;
150  LOG_DEBUG<< Form("EE2ST() isec=%d sec_add=%p secID=%d det=%d\n",isec,(void*)EEsec,secID,det)<<endm;
151 
152  switch (det){
153  case kEndcapEmcTowerId: {//..............................
154  bool hasHit[kEEmcNumSubSectors][kEEmcNumEtas];
155  memset(hasHit,0,sizeof(hasHit));
156  if (EEsec) {
157  tca = EEsec->getTwHits();
158  for(int j=0; j<=tca->GetLast(); j++){
159  EEtwHitDst* t = (EEtwHitDst *) tca->At(j);
160  int eta=t->eta();
161  int sub=t->sub()-'A'+1;
162 
163  // FAST SIMU:
164  int adc=(int) (t->energy() * mfixTgain[eta-1]);
165  if(adc<0) adc=0; if (adc> getMaxAdc()) adc=getMaxAdc();
166 
167  StEmcRawHit* h = new StEmcRawHit(id,secID,eta,sub,adc,t->energy());
168  d->addHit(h);
169  hasHit[sub-1][eta-1] = true;
170  // printf("yyy secID=%d, id2=%d\n",isec,h->module());
171  LOG_DEBUG<< Form("Tw %c %d %f %d \n",t->sub(),t->eta(),t->energy(),adc)<<endm;
172  }
173  }
174  if (mUseFullTower) {
175  // Fill rest of detector with empty hits (ADC=0, E=0)
176  for (int sub = 1; sub <= kEEmcNumSubSectors; ++sub)
177  for (int eta = 1; eta <= kEEmcNumEtas; ++eta)
178  if (!hasHit[sub-1][eta-1]) d->addHit(new StEmcRawHit(id,secID,eta,sub,0,0));
179  }
180  } break;
181 
182  case kEndcapEmcPreShowerId: {//............................
183  bool hasHit[3*kEEmcNumSubSectors][kEEmcNumEtas];
184  memset(hasHit,0,sizeof(hasHit));
185  if (EEsec) {
186  tca = EEsec->getPre1Hits();
187  for(int j=0; j<=tca->GetLast(); j++){
188  EEtwHitDst* t = (EEtwHitDst *)(* tca)[j];
189  int eta=t->eta();
190  int sub=t->sub()-'A'+1;
191  int adc= (int) (t->energy()* getPreshowerGain());
192  if(adc<0) adc=0; if (adc> getMaxAdc()) adc=getMaxAdc();
193 
194  StEmcRawHit* h = new StEmcRawHit(id,secID,eta,sub,adc,t->energy());
195  d->addHit(h);
196  hasHit[sub-1][eta-1] = true;
197  LOG_DEBUG<< Form("Pr1 %c %d adc=%d e=%f\n",t->sub(),t->eta(),adc,t->energy())<<endm;
198  }
199 
200  tca = EEsec->getPre2Hits();
201  for(int j=0; j<=tca->GetLast(); j++){
202  EEtwHitDst* t = (EEtwHitDst *)(* tca)[j];
203  int eta=t->eta();
204  int sub=t->sub()-'A'+5+1;
205  int adc= (int) (t->energy()* getPreshowerGain());
206  if(adc<0) adc=0; if (adc> getMaxAdc()) adc=getMaxAdc();
207 
208  StEmcRawHit* h = new StEmcRawHit(id,secID,eta,sub,adc,t->energy());
209  d->addHit(h);
210  hasHit[sub-1][eta-1] = true;
211  LOG_DEBUG<< Form("Pr2 %c %d %d %f\n",t->sub(),t->eta(),adc,t->energy())<<endm;
212  }
213 
214  tca = EEsec->getPostHits();
215  for(int j=0; j<=tca->GetLast(); j++){
216  EEtwHitDst* t = (EEtwHitDst *)(* tca)[j];
217  int eta=t->eta();
218  int sub=t->sub()-'A'+10+1;
219  int adc= (int) (t->energy()* getPreshowerGain());
220  if(adc<0) adc=0; if (adc> getMaxAdc()) adc=getMaxAdc();
221 
222  StEmcRawHit* h = new StEmcRawHit(id,secID,eta,sub,adc,t->energy());
223  d->addHit(h);
224  hasHit[sub-1][eta-1] = true;
225  LOG_DEBUG<< Form ("Post %c %d %d %f\n",t->sub(),t->eta(),adc,t->energy())<<endm;
226  }
227  }
228  if (mUseFullPreShower) {
229  // Fill rest of detector with empty hits (ADC=0, E=0)
230  for (int sub = 1; sub <= 15; ++sub)
231  for (int eta = 1; eta <= kEEmcNumEtas; ++eta)
232  if (!hasHit[sub-1][eta-1]) d->addHit(new StEmcRawHit(id,secID,eta,sub,0,0));
233  }
234  } break;
235 
236  case kEndcapSmdUStripId: { //............................
237  bool hasHit[kEEmcNumStrips];
238  memset(hasHit,0,sizeof(hasHit));
239  if (EEsec) {
240  tca = EEsec->getSmdUHits();
241 
242  for(int j=0; j<=tca->GetLast(); j++){
243  EEsmdHitDst* t = (EEsmdHitDst *)(* tca)[j];
244  int eta=t->strip();
245  int sub=1;
246  int adc= (int) (t->energy()* getSmdGain());
247  if(adc<0) adc=0; if (adc> getMaxAdc()) adc=getMaxAdc();
248 
249  StEmcRawHit* h = new StEmcRawHit(id,secID,eta,sub,adc,t->energy());
250  d->addHit(h);
251  hasHit[eta-1] = true;
252  LOG_DEBUG<< Form("SMDU %d %d %f\n",t->strip(),adc,t->energy())<<endm;
253  }
254  }
255  if (mUseFullSmdu) {
256  // Fill rest of detector with empty hits (ADC=0, E=0)
257  for (int eta = 1; eta <= kEEmcNumStrips; ++eta)
258  if (!hasHit[eta-1]) d->addHit(new StEmcRawHit(id,secID,eta,1,0,0));
259  }
260  } break;
261 
262  case kEndcapSmdVStripId: {//............................
263  bool hasHit[kEEmcNumStrips];
264  memset(hasHit,0,sizeof(hasHit));
265  if (EEsec) {
266  tca = EEsec->getSmdVHits();
267  for(int j=0; j<=tca->GetLast(); j++){
268  EEsmdHitDst* t = (EEsmdHitDst *)(* tca)[j];
269  int eta=t->strip();
270  //int sub=1;
271  int sub=2;
272  int adc= (int) (t->energy()*getSmdGain());
273  if(adc<0) adc=0; if (adc> getMaxAdc()) adc=getMaxAdc();
274 
275  StEmcRawHit* h = new StEmcRawHit(id,secID,eta,sub,adc,t->energy());
276  LOG_DEBUG<< Form("SMDV %d %d %f\n",t->strip(),adc,t->energy())<<endm;
277  d->addHit(h);
278  hasHit[eta-1] = true;
279  }
280  }
281  if (mUseFullSmdv) {
282  // Fill rest of detector with empty hits (ADC=0, E=0)
283  for (int eta = 1; eta <= kEEmcNumStrips; ++eta)
284  if (!hasHit[eta-1]) d->addHit(new StEmcRawHit(id,secID,eta,2,0,0));
285  }
286  } break;
287  default:
288  assert(1==2); // the det is out of range, this code gaves up
289  }
290  }
291  }
292 }
293 
294 
295 
298 
299 Float_t StEEmcFastMaker::getSamplingFraction()
300 {
301  // Returns the sampling fraction used by the fast simulator
302  // to simulate ADC response of the towers.
303  // Updated to 4.8% from Ilya's study http://drupal.star.bnl.gov/STAR/node/16426
304  return 0.048;
305 }
306 
307 Float_t *StEEmcFastMaker::getTowerGains()
308 {
309  // Returns the array of tower gains used by the fast simulator
310  // to simulate ADC response of the towers.
311 
312  // towers are gain matched to fixed E_T: ADC=4096 --> ET=60 GeV
313  const float feta[kEEmcNumEtas]= {1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115};
314  // static Float_t mygains[kEEmcNumEtas];
315  Float_t *mygains=new Float_t[kEEmcNumEtas]; // small memory leak
316  int i;
317  Float_t msamplingFraction = getSamplingFraction();
318  Int_t maxEtot=getMaxET();
319  Int_t maxAdc=getMaxAdc();
320  for (i=0;i<kEEmcNumEtas;i++) {
321  mygains[i]=maxAdc/maxEtot/cosh(feta[i])/msamplingFraction;
322  }
323  return mygains;
324 }
325 
327 {
328  // Returns the (single) constant "gain" used to convert geant
329  // energy to ADC response in the SMD.
330  return 23000; //(adc=g*de )
331 }
332 
334 {
335  // Returns the (single) constant "gain" used to convert geant
336  // energy in the Pre- and Postshower detectors.
337  return 23000; //(adc=g*de )
338 }
339 
342 
343 // $Log: StEEmcFastMaker.cxx,v $
344 // Revision 1.23 2010/08/05 21:23:45 stevens4
345 // Update sampling fraction to 4.8%
346 //
347 // Revision 1.22 2010/07/29 16:12:03 ogrebeny
348 // Update after the peer review
349 //
350 // Revision 1.21 2009/12/09 20:38:00 ogrebeny
351 // User-switchable function added to always create all hits, even if ADC=0. Requested by Pibero for the trigger simulator.
352 //
353 // Revision 1.20 2007/04/28 17:56:01 perev
354 // Redundant StChain.h removed
355 //
356 // Revision 1.19 2007/03/23 03:26:23 balewski
357 // Corretions from Victor
358 //
359 // Revision 1.18 2007/02/16 04:08:43 balewski
360 // bug fix: adc was not limitted to [0,4095], fixed for all layers
361 //
362 // Revision 1.17 2007/01/24 21:07:01 balewski
363 // 1) no cout or printf, only new Logger
364 // 2) EndcapMixer:
365 // - no assert()
366 // - locks out on first fatal error til the end of the job
367 //
368 // Revision 1.16 2007/01/12 23:57:13 jwebb
369 // Calculation of ideal gains moved into static member function getTowerGains()
370 // to allow slow simulator to access them.
371 //
372 // Revision 1.15 2005/06/09 20:04:23 balewski
373 // upgrade for embedding
374 //
375 // Revision 1.14 2005/06/03 19:20:47 balewski
376 // *** empty log message ***
377 //
378 // Revision 1.13 2004/10/20 22:46:36 balewski
379 // add emcCollection if not exist
380 //
381 // Revision 1.12 2004/05/26 21:28:37 jwebb
382 // o Changes to StEEmcFastMaker to provide methods to get sampling fraction,
383 // gains, etc...
384 //
385 // o StMuEEmcSimuMaker is now just a shell of its former self
386 //
387 // o Added StMuEEmcSimuReMaker. This maker takes a muDst as input, and uses
388 // the database maker to "massage" the ADC response, to better simulate
389 // the calorimeter as installed. For now, it simply uses the geant
390 // energy response, combined with a single sampling fraction and the
391 // database gains and pedestals to come up with a new ADC response.
392 //
393 // Revision 1.11 2004/04/08 21:33:25 perev
394 // Leak off
395 //
396 // Revision 1.10 2004/04/08 16:28:08 balewski
397 // *** empty log message ***
398 //
399 // Revision 1.9 2004/03/25 18:13:56 balewski
400 // cleanup
401 //
402 // Revision 1.8 2004/03/24 19:37:55 balewski
403 // be quiet
404 //
405 // Revision 1.7 2003/11/12 19:58:31 balewski
406 // bug for pre2 in StEvent fixed (was either copy of pre1 or garbage)
407 //
408 // Revision 1.6 2003/09/11 05:49:17 perev
409 // ansi corrs
410 //
411 // Revision 1.5 2003/02/21 15:31:18 balewski
412 // do not kill the chain (it is against my will, JB)
413 //
414 // Revision 1.4 2003/02/20 05:15:51 balewski
415 // *** empty log message ***
416 //
417 // Revision 1.3 2003/02/18 19:56:03 balewski
418 // add pedestals
419 //
420 // Revision 1.2 2003/02/14 00:04:31 balewski
421 // remove few printouts
422 //
423 // Revision 1.1 2003/01/28 23:12:59 balewski
424 // star
425 //
426 
427 
428 
429 
430 
StEEmcFastMaker(const char *name="EEmcFastSim")
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
static Float_t getPreshowerGain()
(adc=g*de ) fixed gain for pre/post shower
static Float_t getSmdGain()
(adc=g*de ) fixed gain for SMD
Definition: Stypes.h:40
virtual void Clear(Option_t *opts="")
Clear the maker for next event.
virtual Int_t Make()