StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
runTrigTreeMaker.C
1 // Based on the macro StRoot/StTriggerUtilities/macros/rdMu2TrigSimu.C as of August 20th, 2012
2 
3 // Before running macro create an output directory "outL2" if you want a copy of the L2 output histos
4 // This macro runs on real data (flagMC=0) and MC files (flagMC=1)
5 // Set flag ==1 for those detectors you want included in the trigger decisions
6 // Set configuration for BEMC (online, offline or custom). EEMC is the same for offline and online
7 // Choose the correct configuration year if you want to use L2
8 
9 // designed for 2006
10 
11 int total=0;
12 class StChain *chain=0;
13 
14 // make sure the eemcSetupPath ends with a '/' and has a subdirectory for the
15 // year of interest
16 
17 void runTrigTreeMaker( const Char_t *file="rcf10063_2_6000evts.MuDst.root", const Char_t* fileOut = "rcf10063_2_6000evts.TrigTree-A.root", Char_t trigVer = 'g', Int_t nevents = 10000000,
18  Int_t flagMC = 1, const Char_t *eemcSetupPath="/star/u/sgliske/Share/StarTrigSimuSetup/" ){
19 
20  //int flagMC=0; // 0/1 == Using Real/Simulation data files
21  int useEemc=2; // 0/1 == Exclude/Include EEMC in Trigger Decisions
22  int useBemc=0; // 0/1 == Exclude/Include BEMC in Trigger Decisions
23  int useL2=1; // 0/1 == Exclude/Include L2 in Trigger Decisions
24  int L2ConfigYear=2006; // possible: 2006, 2008
25  int bemcConfig=1; // Online==1, Offline==2, Expert==3
26  int playConfig=0; // jan:100_199
27  int emcEveDump=0; // extrating raw EMC data in a custom format
28  int outputL2Histo=1;//output L2 histos to directory outL2
29  TString outDir="./outL2/";
30 
31  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
32  loadSharedLibraries();
33  assert( !gSystem->Load("StDetectorDbMaker"));
34  assert( !gSystem->Load("StTpcDb"));
35  assert( !gSystem->Load("StDbUtilities"));
36  assert( !gSystem->Load("StDbBroker"));
37  assert( !gSystem->Load("St_db_Maker"));
38  assert( !gSystem->Load("StEEmcUtil")); // needed by eemcDb
39  assert( !gSystem->Load("StEEmcDbMaker"));
40  assert( !gSystem->Load("StDaqLib")); // needed by bemcDb
41  assert( !gSystem->Load("StEmcRawMaker"));
42  assert( !gSystem->Load("StEmcADCtoEMaker"));
43  if (flagMC) {
44  assert( !gSystem->Load("StMcEvent"));
45  assert( !gSystem->Load("StMcEventMaker"));
46  assert( !gSystem->Load("StEmcSimulatorMaker"));
47  assert( !gSystem->Load("StEEmcSimulatorMaker"));
48  assert( !gSystem->Load("StEpcMaker"));
49  }
50  assert( !gSystem->Load("StTriggerUtilities"));
51  assert( !gSystem->Load("StSpinDbMaker") );
52  assert( !gSystem->Load("StEEmcPoolEEmcTreeContainers") );
53  assert( !gSystem->Load("StEEmcTreeMaker") );
54 
55  gROOT->Macro("LoadLogger.C");
56  cout << " loading done " << endl;
57 
58  chain= new StChain("StChain");
59 
60  if (flagMC){
61  TString geantFile;
62  geantFile += file;
63  geantFile.ReplaceAll("MuDst.root", "geant.root");
64  printf("geantFile=%s\n", geantFile.Data());
65  StIOMaker* ioMaker = new StIOMaker();
66  ioMaker->SetFile(geantFile);
67  ioMaker->SetIOMode("r");
68  ioMaker->SetBranch("*",0,"0"); //deactivate all branches
69  ioMaker->SetBranch("geantBranch",0,"r"); //activate geant Branch
70  StMcEventMaker *evtMaker = new StMcEventMaker();
71  }
72 
73  //Need MuDstMaker to get data
74  printf(" Analyzing file=%s\n",file);
75  StMuDstMaker* muDstMaker =new StMuDstMaker(0,0,"",file,"",1000);
76 
77  // just to make sure StEvent is found for the trig simu
78  StMuDst2StEventMaker *muDst2StEvent = new StMuDst2StEventMaker();
79 
80  //Database -- get a real calibration from the database
81  St_db_Maker* dbMk =0;
82  if(useEemc || useL2) // full DB access
83  dbMk = new St_db_Maker("StarDb","MySQL:StarDb","MySQL:StarDb","$STAR/StarDb");
84  else // only Barrel is uploaded, is faster
85  dbMk = new St_db_Maker("Calibrations","MySQL:Calibrations_emc");
86  dbMk->SetAttr("blacklist", "fgt");
87  dbMk->SetAttr("blacklist", "svt");
88  dbMk->SetAttr("blacklist", "tpc");
89  dbMk->SetAttr("blacklist", "ftpc");
90 
91 
92  // CORRECTION: do not always need to set date and time for MC
93  //If MC then must set database time and date
94  //If Endcap fast simu is used tower gains in DB do not matter,JB
95  //if (flagMC) dbMk->SetDateTime(20060522, 55000);//timestamp R7142018
96 
97  //Collect all output histograms
98  TObjArray* HList=new TObjArray;
99 
100  //Endcap DB
101  if(useEemc || useL2) new StEEmcDbMaker("eemcDb");
102 
103 
104  //Get BEMC adc values
105  if (flagMC && useBemc) {
106  StEmcSimulatorMaker* emcSim = new StEmcSimulatorMaker(); //use this instead to "redo" converstion from geant->adc
107  if (bemcConfig == 1) {
108  emcSim->setCheckStatus(kBarrelEmcTowerId,false); //this returns hits regardless of offline tower status
109  }
110  emcSim->setCalibSpread(kBarrelEmcTowerId,0.15);//spread gains by 15%
111  }
112  if (flagMC==0 && useBemc){
113  StEmcADCtoEMaker *bemcAdc = new StEmcADCtoEMaker();//for real data this sets calibration and status
114  if (bemcConfig == 1) {
115  bemcAdc->setCheckStatus(kBarrelEmcTowerId,false);
116  }
117  }
118 
119  // original comment: must use slow simulator to get pedestals
120  // correct for L2. New comment: I think this is needed if slow simulator was
121  // used in the MC production.
122  if (0 && flagMC==1 && useEemc){
123  StEEmcSlowMaker *slowSim = new StEEmcSlowMaker("slowSim");
124 
125  // note: changing the sampling fraction does not effect the
126  // L0 trigger decision. Also, it is probably better to use the value
127  // in the slow simulator, so that it matches data. (S. Gliske,
128  // Sept 2012)
129 
130  // This 1.3 comes from the iron/air MC, where the sampling
131  // fraction was believed to be near 4%, but slow/fast simulator
132  // used 5%.
133 
134  // Now that the slow/fast simulator uses 0.048, it is a 1.25 scaling factor
135 
136  // slowSim->setSamplingFraction(0.0384); // effectively scale all Tower energies with a factor of 1.3 (added by: Ilya Selyuzhenkov; April 11, 2008)
137 
138  slowSim->setAddPed(true);
139  slowSim->setSmearPed(true);
140  }
141 
142  //Get TriggerMaker
143  StTriggerSimuMaker *simuTrig = new StTriggerSimuMaker("StarTrigSimu");
144  simuTrig->setHList(HList);
145  simuTrig->setMC(flagMC); // must be before individual detectors, to be passed
146  simuTrig->useBbc();
147  if(useEemc) {
148  simuTrig->useEemc(0);//default=0:just process ADC, 1,2:comp w/trgData,see .
149  simuTrig->eemc->setSetupPath(eemcSetupPath);
150  }
151  if(useBemc){
152  simuTrig->useBemc();
153  simuTrig->bemc->setConfig(bemcConfig);
154  }
155 
156  if(flagMC && useEemc==2){
157  // pass one argument to M-C as generic switch
158  // Endcap specific params -- ok Jan you need to change this to a default "online" setup
159  int eemcDsmSetup[20]; // see StEemcTriggerSimu::initRun() for definition
160  memset(eemcDsmSetup, 0,sizeof(eemcDsmSetup));// clear all, may be a bad default
161 
162  if( trigVer == 'd' ){
163  // valid runs 7130037-7132029
164  eemcDsmSetup[0]=6; // HTthr0
165  eemcDsmSetup[1]=12; // HTthr1
166  eemcDsmSetup[2]=22; // HTthr2
167  eemcDsmSetup[3]=1; // TPthr0
168  eemcDsmSetup[4]=20; // TPthr1
169  eemcDsmSetup[5]=31; // TPthr2
170  } else if ( trigVer == 'e' ){
171  // valid runs 7132045-7133051
172  eemcDsmSetup[0]=6; // HTthr0
173  eemcDsmSetup[1]=17; // HTthr1
174  eemcDsmSetup[2]=22; // HTthr2
175  eemcDsmSetup[3]=1; // TPthr0
176  eemcDsmSetup[4]=20; // TPthr1
177  eemcDsmSetup[5]=31; // TPthr2
178  } else if ( trigVer == 'f' ){
179  // valid runs 7133052-7156040
180  eemcDsmSetup[0]=6; // HTthr0
181  eemcDsmSetup[1]=16; // HTthr1
182  eemcDsmSetup[2]=22; // HTthr2
183  eemcDsmSetup[3]=1; // TPthr0
184  eemcDsmSetup[4]=20; // TPthr1
185  eemcDsmSetup[5]=31; // TPthr2
186  } else if ( trigVer == 'g' ){
187  // test trigger, ht1 & tp2 are 1 DSM (roughly 5%) higher than 'e'
188  eemcDsmSetup[0]=6; // HTthr0
189  eemcDsmSetup[1]=18; // HTthr1
190  eemcDsmSetup[2]=22; // HTthr2
191  eemcDsmSetup[3]=1; // TPthr0
192  eemcDsmSetup[4]=21; // TPthr1
193  eemcDsmSetup[5]=31; // TPthr2
194  } else if ( trigVer == 'h' || trigVer == 'i' ){
195  // test trigger, ht1 & tp2 are 2 DSM (roughly 10%) higher than 'e'
196  eemcDsmSetup[0]=6; // HTthr0
197  eemcDsmSetup[1]=19; // HTthr1
198  eemcDsmSetup[2]=22; // HTthr2
199  eemcDsmSetup[3]=1; // TPthr0
200  eemcDsmSetup[4]=22; // TPthr1
201  eemcDsmSetup[5]=31; // TPthr2
202  } else {
203  cerr << "Invalid trigger version" << endl;
204  return;
205  };
206  eemcDsmSetup[10]=2; //HTTPthrSelc, 2=use_thres_#1
207 
208  simuTrig->eemc->setDsmSetup(eemcDsmSetup);
209  }
210 
211 
212  StGenericL2Emulator* simL2Mk=0;
213  if(useL2) {
214  /*
215  NOTE: the following comment was in the rdMu2TrigSimu.C macro,
216  but does not seem applicable. Just use the given
217  StarTrigSimuSetup directory, and make sure the given outDir
218  exists, all will be well.
219 
220  reads all input/setup files from L2setup-yyyymmdd/
221  writes all output files to L2out-yyyymmdd
222  depending on the DB time stamp
223  both dierectiorie MUST exist, setup must be reasonable
224  */
225  if(L2ConfigYear==2006) simL2Mk= new StL2_2006EmulatorMaker;
226  else if(L2ConfigYear==2008) simL2Mk= new StL2_2008EmulatorMaker;
227  assert(simL2Mk);
228  simL2Mk->setSetupPath(eemcSetupPath);
229 
230  simL2Mk->setOutPath(outDir.Data());
231  if (flagMC) simL2Mk->setMC();
232  simuTrig->useL2(simL2Mk);
233  }
234 
235  // now the maker to write the tree
236  StTrigTreeMaker_t *treeMkr = new StTrigTreeMaker_t( "trigTreeMaker", fileOut, 1 );
237  treeMkr->addTrigger( -999 ); // i.e. no trigger cut now
238 
239  chain->ls(3);
240 
241  cout << "******* Initialize *******" << endl ;
242  chain->Init();
243  cout << "******* done with initializing *******" << endl;
244 
245  for (Int_t iev=0;iev<nevents; iev++) {
246  if( iev % 100 == 1 )
247  cout << "Working on eventNumber:\t" << iev <<"\tof:\t"<<nevents<<endl;
248 
249  chain->Clear();
250  int iret = chain->Make(iev);
251  total++;
252  if (iret % 10 == kStEOF || iret % 10 == kStFatal) {
253  cout << iev << " Bad return code!" << endl;
254  break;
255  }
256 
257  //struct L2gammaResult2006* result = dynamic_cast< L2gammaResult2006* >( simL2Mk->result() );
258  //cout << "ZZZ " << result->trigger << endl;
259 
260  if( simL2Mk ){
261 // const unsigned int* result = simL2Mk->result();
262 // cout << "ZZZ " << std::hex << result[0] << result[1] << result[2] << result[3] << result[4] << result[5] << result[6] << result[7] << std::dec
263 // << " " << simL2Mk->mAcceptTriggerList.size() << ' ' << simL2Mk->mVetoTriggerList.size() << endl;
264 
265 // cout << "ZZZ accept: ";
266 // for( Int_t i=0; i<simL2Mk->mAcceptTriggerList.size(); ++i )
267 // cout << simL2Mk->mAcceptTriggerList.at(i) << ' ';
268 // cout << endl;
269 
270 // cout << "ZZZ veto: ";
271 // for( Int_t i=0; i<simL2Mk->mVetoTriggerList.size(); ++i )
272 // cout << simL2Mk->mVetoTriggerList.at(i) << ' ';
273 // cout << endl;
274 
275 // cout << "ZZZ " << simuTrig->isTrigger( 137641 ) << endl;
276  }
277  }
278 
279 
280  chain->Finish();
281  cout << "****************************************** " << endl;
282  cout << "total number of events " << total << endl;
283  cout << "****************************************** " << endl;
284 
285  if (outputL2Histo==1) {
286 
287  TString fileMu=file;
288  printf("=%s=\n",fileMu.Data());
289  if(fileMu.Contains(".lis")) fileMu.ReplaceAll(".lis",".trgSim");
290  if(fileMu.Contains(".MuDst.root")) fileMu.ReplaceAll(".MuDst.root",".trgSim");
291  TString outF=outDir+fileMu;
292  outF+=".hist.root";
293  printf("=%s=\n",outF.Data());
294  hf=new TFile(outF,"recreate");
295  if(hf->IsOpen()) {
296  cout << "HList not saved, or seg faults" << endl;
297  //HList->Write();
298  //printf("\n Histo saved -->%s<\n",outF.Data());
299  }
300  else {
301  printf("\n Failed to open Histo-file -->%s<, continue\n",outF.Data());
302  }
303  }
304 
305 }
306 
307 /*
308  * $Id: runTrigTreeMaker.C,v 1.2 2013/01/11 17:32:29 sgliske Exp $
309  * $Log: runTrigTreeMaker.C,v $
310  * Revision 1.2 2013/01/11 17:32:29 sgliske
311  * bug fix
312  *
313  * Revision 1.1 2013/01/11 16:14:21 sgliske
314  * copied from users/sgliske CVS area
315  *
316  *
317  */
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)
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
void setSmearPed(Bool_t s=true)
Smear the pedestal with sigma from DB.
Slow simulator for EEMC.
void setCalibSpread(StDetectorId det, float spread)
smear simulator calibration coefficients using Gaussian with this RMS.
void setCheckStatus(StDetectorId det, int flag, const char *option="")