StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
electron_histogram_maker.C
1 //Contrary to its name, this code does not make histograms. Rather, it skims the trees looking for electrons
2 //and writes them to a slimmer tree
3 #include <iostream>
4 #include <fstream>
5 #include <vector>
6 #include <set>
7 //#include <StTriggerUtilities/L2Emulator/L2wAlgo/L2wResult2009.h>
8 using namespace std;
9 
10 struct L2wResult2009 { // must be N*4 bytes
11  enum {mySizeChar=8};// negotiate size w/ Ross before extending
12  unsigned char seedEt; // seed Et with 60Gev Max. bits=Et*256/60
13  unsigned char clusterEt; // cluster Et with 60Gev Max. bits=Et*256/60
14  unsigned char seedEtaBin; // iEta bin
15  unsigned char seedPhiBin; // iPhi bin
16 
17  unsigned char trigger; // bit0=rnd, bit1=ET>thr
18  unsigned char dum1,dum2,dum3;
19 };
20 
21 
22 void electron_histogram_maker(const char* file_list="ctest.list",const char* skimfile="electronskimfile.root")
23 {
24  gROOT->Macro("LoadLogger.C");
25  gROOT->Macro("loadMuDst.C");
26  gSystem->Load("StTpcDb");
27  gSystem->Load("StDaqLib");
28  gSystem->Load("StDetectorDbMaker");
29  gSystem->Load("St_db_Maker");
30  gSystem->Load("StDbUtilities");
31  gSystem->Load("StEmcRawMaker");
32  gSystem->Load("StMcEvent");
33  gSystem->Load("StMcEventMaker");//***
34  gSystem->Load("StEmcSimulatorMaker");//***
35  gSystem->Load("StEmcADCtoEMaker");
36  gSystem->Load("StEpcMaker");
37  gSystem->Load("StDbBroker");
38  gSystem->Load("StEmcUtil");
39  gSystem->Load("StAssociationMaker");
40  //gSystem->Load("StEmcTriggerMaker");
41  gSystem->Load("StTriggerUtilities");
42  gSystem->Load("StEmcOfflineCalibrationMaker");
43  cout<<"input filelist: "<<file_list<<endl;
44  cout<<"skimmed tree: "<<skimfile<<endl;
45 
46  //chain all input files together
47  char file[300];
48  TChain* calib_tree = new TChain("calibTree");
49  ifstream filelist(file_list);
50  while(1){
51  filelist >> file;
52  if(!filelist.good()) break;
53  cout<<file<<endl;
54  calib_tree->Add(file);
55  }
56 
57  StEmcGeom* geom = StEmcGeom::instance("bemc");
58 
59 
60  vector<unsigned int> htTriggers;
61  htTriggers.push_back(240530);
62  htTriggers.push_back(240530);
63  htTriggers.push_back(240550);
64  htTriggers.push_back(240560);
65  htTriggers.push_back(240570);
66 
67  /*
68  htTriggers.push_back(230531);
69  htTriggers.push_back(230601);
70  */
71 
72  /*
73  htTriggers.push_back(220500);
74  htTriggers.push_back(220510);
75  htTriggers.push_back(220520);
76  */
78  calib_tree->SetBranchAddress("event_branch",&myEvent);
82 
83  TFile* skim_file = new TFile(skimfile,"RECREATE");
84  TTree *electron_tree = new TTree("skimTree","electron tracks");
85  electron_tree->Branch("clusters",&cluster);
86 
87  TH2F* dEdxvsp = new TH2F("dEdxvsp","",100,0.0,10.0,100,0.0,1e-5);
88 
89  //keep track of all hit towers and exclude any with >1 track/tower
90  set<int> track_towers;
91  set<int> excluded_towers;
92 
93  unsigned int nAccept = 0;
94  unsigned int nGoodEvents = 0;
95  unsigned int nentries = calib_tree->GetEntries();
96  int ngoodhit = 0;
97  int nplt10 = 0;
98  int nnosis = 0;
99  int nfinal = 0;
100  int nbsmdgood = 0;
101  int nnottrig = 0;
102  int nfidu = 0;
103  int nenterexit = 0;
104  for(unsigned int i=0; i<nentries; i++){
105  if(i%1000000 == 0) cout<<"processing "<<i<<" of "<<nentries<<endl;
106  //cout<<i<<endl;
107  calib_tree->GetEntry(i);
108 
109  //event level cuts
110  if(TMath::Abs(myEvent->vz[0]) > 60.) continue;
111 
112  //TArrayI& l2Array = myEvent->l2Result;
113  //unsigned int *l2res=(unsigned int *)l2Array.GetArray();
114  //printf(" L2-jet online results below:\n");
115  const int BEMCW_off=20; // valid only for 2009 run
116  //L2wResult2009* l2wresult = NULL;
117  //l2wresult = (L2wResult2009*) &l2res[BEMCW_off];
118  //int l2wbit = (l2wresult->trigger&2)>0;
119  //int l2wrnd = (l2wresult->trigger&1)>0;
120  float trigeta = -999;
121  float trigphi = -999;
122 
123  //cout<<i<<" "<<l2wbit<<" "<<l2wrnd<<endl;
124 
125  /*
126  if(l2wbit || l2wrnd){
127  trigeta = (float)(l2wresult->seedEtaBin - 1)*0.05-1 + 0.025;
128  int kPhi = l2wresult->seedPhiBin;
129  if(kPhi > 24)kPhi -= 120;
130  trigphi = (float)(24 - kPhi)*TMath::Pi()/60.;
131  if(trigphi > TMath::Pi())trigphi -= 2*TMath::Pi();
132  }
133  */
134  int nht = 0;
135  int yht = 0;
136  for(unsigned int h = 0; h < myEvent->triggerIds.size(); h++){
137  int isht = 0;
138  for(unsigned int f = 0; f < htTriggers.size(); f++){
139  if(htTriggers[f] == myEvent->triggerIds[h])isht = 1;
140  }
141  if(!isht)nht = 1;
142  if(isht)yht = 1;
143  //cout<<i<<" "<<myEvent->triggerIds[h]<<endl;
144  }
145  //cout<<i<<" "<<nht<<" "<<yht<<endl;
146  //if(!nht && yht)continue;
147  //do a quick loop over tracks to get excluded towers
148  track_towers.clear();
149  excluded_towers.clear();
150 
151  for(int j=0; j<myEvent->tracks->GetEntries(); j++){
152  track = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
153  int id = track->tower_id[0];
154 
155  if(track_towers.find(id) != track_towers.end()){
156  excluded_towers.insert(id);
157  }
158  else{
159  track_towers.insert(id);
160  }
161  }
162 
163  //now we loop again and look for electrons / hadrons
164  for(int j=0; j<myEvent->tracks->GetEntries(); j++){
165  track = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
166  dEdxvsp->Fill(track->p,track->dEdx);
167  if(j==0) nGoodEvents++;
168 
169  double dR = TMath::Sqrt(track->deta*track->deta + track->dphi*track->dphi);
170  //if(dR > 0.03) continue;
171  //cout<<track->nSigmaElectron<<" "<<track->p<<" "<<track->nHits<<" "<<track->tower_id[0]<<" "<<track->tower_id_exit<<endl;
172  float squarefid = 0.03/TMath::Sqrt(2.0);
173  //if(TMath::Abs(track->deta) > squarefid || TMath::Abs(track->dphi) > squarefid)continue;
174 
175  if(track->p < 1.5) continue;
176  if(track->p > 20.) continue;
177  ngoodhit++;
178  if(track->tower_status[0] != 1) continue;
179  nenterexit++;
180  //if(track->tower_id[0] != track->tower_id_exit) continue;
181  if(track->nHits < 10) continue;
182  nplt10++;
183  //if(track->vertexIndex != 0) continue;
184 
185  if(excluded_towers.find(track->tower_id[0]) != excluded_towers.end()) continue;
186  nfidu++;
187  if((track->tower_adc[0] - track->tower_pedestal[0]) < 1.5 * track->tower_pedestal_rms[0])continue;
188  nnottrig++;
189  //cout<<track->dEdx<<endl;
190  if(track->dEdx < 3.0e-6)continue;
191  nbsmdgood++;
192  //looking for tracks at surrounding towers
193  //cout<<"passed basic cuts"<<endl;
194 
195  //if(track->nSigmaElectron > -2.){
196  //create start using cluster
197  cluster->centralTrack = *track;
198 
199  float toweta,towphi;
200  geom->getEtaPhi(track->tower_id[0],toweta,towphi);
201 
202  int tr = 0;
203  /*
204  if(yht){
205  float tcdeta = fabs(toweta - trigeta);
206  float tcdphi = fabs(towphi - trigphi);
207  if(tcdphi > TMath::Pi())tcdphi -= TMath::Pi();
208  float tcdR = sqrt(pow(tcdeta,2) + pow(tcdphi,2));
209  if(tcdR < 0.7)tr = 1;
210  //cout<<i<<" "<<trigeta<<" "<<trigphi<<" "<<tcdR<<" "<<yht<<" "<<tr<<" "<<nht<<endl;
211  }
212  */
213 
214  track->htTrig = yht + tr;
215  track->nonhtTrig = nht;
216  //cout<<track->htTrig<<endl;
217 
218  for (int k = 1; k < 9; k++)//loop over surrounding towers
219  {
220  if(track_towers.find(track->tower_id[k]) != track_towers.end())//if there's a tower with a track
221  {
222  for(int q = 0; q < myEvent->tracks->GetEntries(); q++)//loop over all of the tracks in the event
223  {
224  if(q == j)continue;//continue if we're looking at the same track
225  dumtrack = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(q);
226  if(dumtrack->tower_id[0] == track->tower_id[k])
227  {
228  cluster->addTrack(dumtrack);
229  //cout<<"Track "<<q<<" added to track "<<j<<" of event "<<i<<"."<<endl;
230  //continue;//track found so exit from this for loop
231  }
232  }
233  }
234  }
235  nAccept++;
236  electron_tree->Fill();
237  track->Clear();
238  cluster->Clear();
239  //}
240  }
241  myEvent->Clear();
242  }
243 
244  cout<<"found "<<nGoodEvents<<" events with at least one good track"<<endl;
245  cout<<"accepted "<<nAccept<<" electrons"<<endl;
246  //cout<<"ngoodhit: "<<ngoodhit<<endl;
247  //cout<<"nenterexit: "<<nenterexit<<endl;
248  //cout<<"n p < 10: "<<nplt10<<endl;
249  //cout<<"n in fidu: "<<nfidu<<endl;
250  //cout<<"n not trig: "<<nnottrig<<endl;
251  //cout<<"nbsmdhit: "<<nbsmdgood<<endl;
252  //cout<<"n no sis: "<<nnosis<<endl;
253  //cout<<"n final: "<<nfinal<<endl;
254  skim_file->cd();
255  skim_file->Write();
256  skim_file->Close();
257 }