StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rdMu2TrigSimu.C
1 // Before running macro create an output directory "outL2" if you want a copy of the L2 output histos
2 // This macro runs on real data (flagMC=0) and MC files (flagMC=1)
3 // Set flag ==1 for those detectors you want included in the trigger decisions
4 // Set configuration for BEMC (online, offline or custom). EEMC is the same for offline and online
5 // Choose the correct configuration year if you want to use L2
6 
7 int total=0;
8 class StChain *chain=0;
9 char *eemcSetupPath="/afs/rhic.bnl.gov/star/users/kocolosk/public/StarTrigSimuSetup/";
10 
11 void rdMu2TrigSimu(char *file="/star/data47/reco/pp200/pythia6_410/9_11gev/cdf_a/y2006c/gheisha_on/p07ic/rcf1309_*_2000evts.MuDst.root"){
12 
13  int nevents = 200;
14  int flagMC=1; // 0/1 == Using Real/Simulation data files
15  int useEemc=1; // 0/1 == Exclude/Include EEMC in Trigger Decisions
16  int useBemc=1; // 0/1 == Exclude/Include BEMC in Trigger Decisions
17  int useL2=1; // 0/1 == Exclude/Include L2 in Trigger Decisions
18  int L2ConfigYear=2006; // possible: 2006, 2008
19  int bemcConfig=2; // Online==1, Offline==2, Expert==3
20  int playConfig=0; // jan:100_199
21  int emcEveDump=0; // extrating raw EMC data in a custom format
22  int outputL2Histo=0;//output L2 histos to directory outL2
23  TString outDir="./outL2/";
24 
25 
26  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
27  loadSharedLibraries();
28  assert( !gSystem->Load("StDetectorDbMaker"));
29  assert( !gSystem->Load("StDbUtilities"));
30  assert( !gSystem->Load("StDbBroker"));
31  assert( !gSystem->Load("St_db_Maker"));
32  assert( !gSystem->Load("StEEmcUtil")); // needed by eemcDb
33  assert( !gSystem->Load("StEEmcDbMaker"));
34  assert( !gSystem->Load("StDaqLib")); // needed by bemcDb
35  assert( !gSystem->Load("StEmcRawMaker"));
36  assert( !gSystem->Load("StEmcADCtoEMaker"));
37  if (flagMC) {
38  assert( !gSystem->Load("StMcEvent"));
39  assert( !gSystem->Load("StMcEventMaker"));
40  assert( !gSystem->Load("StEmcSimulatorMaker"));
41  assert( !gSystem->Load("StEEmcSimulatorMaker"));
42  assert( !gSystem->Load("StEpcMaker"));
43  }
44  assert( !gSystem->Load("StTriggerUtilities"));
45 
46  gROOT->Macro("LoadLogger.C");
47  cout << " loading done " << endl;
48 
49  chain= new StChain("StChain");
50 
51  if (flagMC){
52  TString geantFile;
53  geantFile += file;
54  geantFile.ReplaceAll("MuDst.root", "geant.root");
55  printf("geantFile=%s\n", geantFile.Data());
56  StIOMaker* ioMaker = new StIOMaker();
57  ioMaker->SetFile(geantFile);
58  ioMaker->SetIOMode("r");
59  ioMaker->SetBranch("*",0,"0"); //deactivate all branches
60  ioMaker->SetBranch("geantBranch",0,"r"); //activate geant Branch
61  StMcEventMaker *evtMaker = new StMcEventMaker();
62  }
63 
64  //Need MuDstMaker to get data
65  printf(" Analyzing file=%s\n",file);
66  StMuDstMaker* muDstMaker =new StMuDstMaker(0,0,"",file,"",1000);
67 
68  //Database -- get a real calibration from the database
69  St_db_Maker* dbMk =0;
70  if(useEemc || useL2) // full DB access
71  dbMk = new St_db_Maker("StarDb","MySQL:StarDb","MySQL:StarDb","$STAR/StarDb");
72  else // only Barrel is uploaded, is faster
73  dbMk = new St_db_Maker("Calibrations","MySQL:Calibrations_emc");
74 
75 
76  //If MC then must set database time and date
77  //If Endcap fast simu is used tower gains in DB do not matter,JB
78  if (flagMC) dbMk->SetDateTime(20060522, 55000);//timestamp R7142018
79 
80  //Collect all output histograms
81  TObjArray* HList=new TObjArray;
82 
83  //Endcap DB
84  if(useEemc || useL2) new StEEmcDbMaker("eemcDb");
85 
86 
87  //Get BEMC adc values
88  if (flagMC && useBemc) {
89  StEmcSimulatorMaker* emcSim = new StEmcSimulatorMaker(); //use this instead to "redo" converstion from geant->adc
90  if (bemcConfig == 1) {
91  emcSim->setCheckStatus(kBarrelEmcTowerId,false); //this returns hits regardless of offline tower status
92  }
93  emcSim->setCalibSpread(kBarrelEmcTowerId,0.15);//spread gains by 15%
94  }
95  if (flagMC==0 && useBemc){
96  StEmcADCtoEMaker *bemcAdc = new StEmcADCtoEMaker();//for real data this sets calibration and status
97  if (bemcConfig == 1) {
98  bemcAdc->setCheckStatus(kBarrelEmcTowerId,false);
99  }
100  }
101 
102  //must use slow simulator to get pedestals correct for L2
103  if (flagMC==1 && useEemc){
104  StEEmcSlowMaker *slowSim = new StEEmcSlowMaker("slowSim");
105  slowSim->setSamplingFraction(0.0384); // effectively scales all Tower energies with a factor of 1.3 (added by: Ilya Selyuzhenkov; April 11, 2008)
106  slowSim->setAddPed(true);
107  slowSim->setSmearPed(true);
108  }
109 
110  //Get TriggerMaker
111  StTriggerSimuMaker *simuTrig = new StTriggerSimuMaker("StarTrigSimu");
112  simuTrig->setHList(HList);
113  simuTrig->setMC(flagMC); // must be before individual detectors, to be passed
114  simuTrig->useBbc();
115  if(useEemc) {
116  simuTrig->useEemc(0);//default=0:just process ADC, 1,2:comp w/trgData,see .
117  simuTrig->eemc->setSetupPath(eemcSetupPath);
118  }
119  if(useBemc){
120  simuTrig->useBemc();
121  simuTrig->bemc->setConfig(bemcConfig);
122  }
123 
124  if(flagMC && useEemc==2){
125  // pass one argument to M-C as generic switch
126  // Endcap specific params -- ok Jan you need to change this to a default "online" setup
127  int eemcDsmSetup[20]; // see StEemcTriggerSimu::initRun() for definition
128  memset(eemcDsmSetup, 0,sizeof(eemcDsmSetup));// clear all, may be a bad default
129  eemcDsmSetup[0]=3; // HTthr0
130  eemcDsmSetup[1]=12; // HTthr1
131  eemcDsmSetup[2]=22; // HTthr2
132  eemcDsmSetup[3]=1; // TPthr0
133  eemcDsmSetup[4]=17; // TPthr1
134  eemcDsmSetup[5]=31; // TPthr2
135  eemcDsmSetup[10]=2; //HTTPthrSelc, 2=use_thres_#1
136  simuTrig->eemc->setDsmSetup(eemcDsmSetup);
137  }
138 
139 
140  if(useL2) {
141  /*
142  reads all input/setup files from L2setup-yyyymmdd/
143  writes all output files to L2out-yyyymmdd
144  depending on the DB time stamp
145  both dierectiorie MUST exist, setup must be reasonable
146  */
147  StGenericL2Emulator* simL2Mk=0;
148  if(L2ConfigYear==2006) simL2Mk= new StL2_2006EmulatorMaker;
149  else if(L2ConfigYear==2008) simL2Mk= new StL2_2008EmulatorMaker;
150  assert(simL2Mk);
151  simL2Mk->setSetupPath(eemcSetupPath);
152  simL2Mk->setOutPath(outDir.Data());
153  if (flagMC) simL2Mk->setMC();
154  simuTrig->useL2(simL2Mk);
155  }
156 
157 
158  //if(emcEveDump) new StJanEventMaker;
159 
160  StTriggerSimuPlayMaker *playMk= new StTriggerSimuPlayMaker; // to develope user analysis of trigQA
161  playMk->setConfig(playConfig);
162  playMk->setHList(HList);
163 
164 
165  chain->ls(3);
166  chain->Init();
167 
168  for (Int_t iev=0;iev<nevents; iev++) {
169  cout << "\n****************************************** " << endl;
170  cout << "Working on eventNumber:\t" << iev <<"\tof:\t"<<nevents<<endl;
171  cout << "****************************************** " << endl;
172  chain->Clear();
173  int iret = chain->Make(iev);
174  total++;
175  if (iret % 10 == kStEOF || iret % 10 == kStFatal) {
176  cout << "Bad return code!" << endl;
177  break;
178  }
179 
180  int trigID[3]={127213,117211,137611};
181  StMuDst *muDst = muDstMaker->muDst();
182  StMuEvent *muEvent = muDst->event();
183  StMuTriggerIdCollection trig = muEvent -> triggerIdCollection();
184  StTriggerId l1trig = trig.nominal();
185  if( l1trig.isTrigger(trigID[0])) {
186  cout<<" SimuTrigger 127213 ="<<simuTrig->isTrigger(trigID[0])<<" BEMC="<<simuTrig->bemc->triggerDecision(trigID[0])<<" L2="<<simuTrig->lTwo->triggerDecision(trigID[0])<<endl;
187  }
188  if( l1trig.isTrigger(trigID[1])) {
189  cout<<" SimuTrigger 117211 ="<<simuTrig->isTrigger(trigID[1])<<" BEMC="<<simuTrig->bemc->triggerDecision(trigID[1])<<" L2="<<simuTrig->lTwo->triggerDecision(trigID[1])<<endl;
190  }
191  if( l1trig.isTrigger(trigID[2])) {
192  cout<<" SimuTrigger 137611 ="<<simuTrig->isTrigger(trigID[2])<<" BEMC="<<simuTrig->bemc->triggerDecision(trigID[2])<<" L2="<<simuTrig->lTwo->triggerDecision(trigID[2])<<endl;
193  }
194 
195 
196  StTriggerSimuResult trigResult = simuTrig->detailedResult(trigID[2]);
197  if (trigResult.bemcDecision()==1){
198  vector<short> towerId = trigResult.highTowerIds();
199  for (unsigned i=0; i<towerId.size(); i++) {
200  cout<<" LO Trigger BEMC Tower="<<towerId[i]<<" adc="<<trigResult.highTowerAdc(towerId[i])<<endl;
201  }
202  }
203 
204 
205  if (trigResult.l2Decision()==1){
206  vector<short> towerId = trigResult.highTowerIds();
207  for (unsigned i=0; i<towerId.size(); i++) {
208  cout<<" L2 Trigger BEMC Tower="<<towerId[i]<<" adc="<<trigResult.highTowerAdc(towerId[i])<<endl;
209  }
210  }
211 
212  }
213 
214 
215  chain->Finish();
216  cout << "****************************************** " << endl;
217  cout << "total number of events " << total << endl;
218  cout << "****************************************** " << endl;
219 
220 
221  if (outputL2Histo==1) {
222 
223  TString fileMu=file;
224  printf("=%s=\n",fileMu.Data());
225  if(fileMu.Contains(".lis")) fileMu.ReplaceAll(".lis",".trgSim");
226  if(fileMu.Contains(".MuDst.root")) fileMu.ReplaceAll(".MuDst.root",".trgSim");
227  TString outF=outDir+fileMu;
228  outF+=".hist.root";
229  printf("=%s=\n",outF.Data());
230  hf=new TFile(outF,"recreate");
231  if(hf->IsOpen()) {
232  HList->Write();
233  printf("\n Histo saved -->%s<\n",outF.Data());
234  }
235  else {
236  printf("\n Failed to open Histo-file -->%s<, continue\n",outF.Data());
237  }
238  }
239 
240  //cout <<Form("sorting done %d of nEve=%d, CPU rate=%.1f Hz, total time %.1f minute(s) \n\n",total,nEntries,rate,tMnt)<<endl;
241 
242 }
243 
244 
245 
246 
247 //========================================
248 //========================================
249 #if 0
250 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
251 clean it up, Jan
252 
253  const int mxTr=13;
254  int myTrgList[mxTr] ={127580,127551,127271,127571,127821,127831,127575,127622,127221,127611,117705,127501,127652};
255  // prescale as for run 7101015
256  char* myTrgListN[mxTr]={"eemc-http*116","eemc-jp0-mb*221", "eemc-jp1-mb*1", "bemc-jp1*433",
257  "bemc-http-mb-fast*1", "eemc-http-mb-fast*1", "bemc-jp0-etot*979" ,
258  "bemc-jp0-etot-mb-L2jet*2", "bemc-jp1-mb*1", "bemc-http-mb-l2gamma*1",
259  "jpsi-mb*20", "bemc-jp0-mb*909","eemc-jp0-etot-mb-L2jet*2"};
260  int nR[mxTr],nS[mxTr],nRS[mxTr];
261  memset(nR,0, sizeof(nR));
262  memset(nS,0, sizeof(nR));
263  memset(nRS,0, sizeof(nR));
264 
265  int BL1_ADC[6];
266  cout<<Form(" Simu trgSize=%d, firedID:", simuTrig->mTriggerList.size())<<endl;
267  int j;
268  for(j=0; j<simuTrig->mTriggerList.size();j++)
269  cout<<Form("s%d, ", simuTrig->mTriggerList[j]);
270  cout<<"\n";
271 
272 
273  // Access to muDst .......................
274  StMuEvent* muEve = muDstMaker->muDst()->event();
275 
276  StEventInfo &info=muEve->eventInfo();
277  StMuTriggerIdCollection &tic=muEve->triggerIdCollection();
278  vector<unsigned int> trgL=tic.nominal().triggerIds();
279  cout<<Form(" real trgSize=%d, firedID:",trgL.size());
280  for(j=0; j<trgL.size();j++)
281  cout<<Form("r%d, ", trgL[j]);
282  cout<<"\n";
283 
284  //.. compare Simu vs. real
285  for(j=0;j<mxTr;j++) {
286  int trgId=myTrgList[j];
287  bool realT=tic.nominal().isTrigger(trgId);
288  bool simT=simuTrig->isTrigger(trgId); // endcap only, tmp
289  if(realT) nR[j]++;
290  if(realT && simT) nRS[j]++;
291  if(simT) nS[j]++;
292  cout <<Form("C:j=%d trg=%d R=%d S=%d RS=%d",j, myTrgList[j],realT,simT,realT && simT )<<endl;
293  }
294 
295  for(j=0;j<mxTr;j++) {
296  cout <<Form("SUM trg=%d nR=%d nS=%d nRS=%d %s", myTrgList[j], nR[j],nS[j],nRS[j],myTrgListN[j])<<endl;
297  }
298 
299 
300 #endif
void setSamplingFraction(Float_t f)
Changes the sampling fraction from the default in the fast simulator.
StMuDst * muDst()
Definition: StMuDstMaker.h:425
void setAddPed(Bool_t a=true)
Add pedestal offsets from DB.
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
void setCheckStatus(StDetectorId det, bool flag)
int highTowerAdc(short towerId) const
returns DSM ADC if above trigger threshold, otherwise -1
virtual Int_t Finish()
Definition: StChain.cxx:85
Filling of all StMcEvent classes from g2t tables Transform all the data in the g2t tables into the co...
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
Definition: Stypes.h:43
virtual Int_t Make()
Definition: StChain.cxx:110
StTriggerSimuDecision triggerDecision(int trigId)
like isTrigger(), but returns kDoNotCare if detector isn&#39;t a part of the given trigId ...
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
void setSmearPed(Bool_t s=true)
Smear the pedestal with sigma from DB.
const StTriggerSimuResult & detailedResult(int trigId)
returns object containing detailed information about simulation of given trigger
Slow simulator for EEMC.
StTriggerSimuDecision triggerDecision(int trigId)
like isTrigger(), but returns kDoNotCare if detector isn&#39;t a part of the given trigId ...
Collection of trigger ids as stored in MuDst.
void setCalibSpread(StDetectorId det, float spread)
smear simulator calibration coefficients using Gaussian with this RMS.
void setCheckStatus(StDetectorId det, int flag, const char *option="")