00001 #include <iostream>
00002 #include <fstream>
00003 #include <set>
00004 using namespace std;
00005
00006 #include "CalibrationHelperFunctions.cxx"
00007
00008 void mip_ring_fitter(const char* file_list="", const char* skimfile="mipskimfile.root")
00009 {
00010 gROOT->Macro("LoadLogger.C");
00011 gROOT->Macro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
00012 gSystem->Load("StTpcDb");
00013 gSystem->Load("StDaqLib");
00014 gSystem->Load("StDetectorDbMaker");
00015 gSystem->Load("St_db_Maker");
00016 gSystem->Load("StDbUtilities");
00017 gSystem->Load("StEmcRawMaker");
00018 gSystem->Load("StMcEvent");
00019 gSystem->Load("StMcEventMaker");
00020 gSystem->Load("StEmcSimulatorMaker");
00021 gSystem->Load("StEmcADCtoEMaker");
00022 gSystem->Load("StEpcMaker");
00023 gSystem->Load("StDbBroker");
00024 gSystem->Load("StEEmcUtil");
00025 gSystem->Load("StAssociationMaker");
00026 gSystem->Load("StEmcTriggerMaker");
00027
00028 gSystem->Load("StEmcOfflineCalibrationMaker");
00029
00030 const int ntowers=4800;
00031 const int nrings=40;
00032 const bool lookForSwaps=false;
00033
00034 CalibrationHelperFunctions* helper = new CalibrationHelperFunctions();
00035
00036 cout<<"input filelist: "<<file_list<<endl;
00037 cout<<"histogram file: "<<skimfile<<endl;
00038
00039
00040 char file[300];
00041 TChain* calib_tree = new TChain("calibTree");
00042 ifstream filelist(file_list);
00043 TFile *test_file;
00044 while(1){
00045 filelist >> file;
00046 if(!filelist.good()) break;
00047 cout<<file<<endl;
00048 calib_tree->Add(file);
00049 }
00050
00051 StEmcOfflineCalibrationEvent* myEvent = new StEmcOfflineCalibrationEvent();
00052 calib_tree->SetBranchAddress("event_branch",&myEvent);
00053 StEmcOfflineCalibrationTrack* mip;
00054
00055
00056 TH1* ring_histo[nrings];
00057 char name[100];
00058 for(int k=0; k<nrings; k++){
00059 sprintf(name,"ring_histo_%i",k+1);
00060 ring_histo[k] = new TH1D(name,name,250,-50.5,199.5);
00061 }
00062
00063
00064 set<int> track_towers;
00065 set<int> excluded_towers;
00066
00067 unsigned int nentries = calib_tree->GetEntries();
00068 for(unsigned int i=0; i<nentries; i++){
00069 if(i%100000 == 0) cout<<"processing "<<i<<" of "<<nentries<<endl;
00070
00071 track_towers.clear();
00072 excluded_towers.clear();
00073
00074 calib_tree->GetEntry(i);
00075
00076
00077 if(TMath::Abs(myEvent->vz[0]) > 30.) continue;
00078
00079
00080 for(int j=0; j<myEvent->tracks->GetEntries(); j++){
00081 mip = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
00082 int id = mip->tower_id[0];
00083
00084 if(track_towers.find(id) != track_towers.end()){
00085 excluded_towers.insert(id);
00086 }
00087 else{
00088 track_towers.insert(id);
00089 }
00090 }
00091
00092
00093
00094
00095 for(int j=0; j<myEvent->tracks->GetEntries(); j++){
00096 mip = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 double pedsub = mip->tower_adc[0] - mip->tower_pedestal[0];
00132
00133 if(mip->p < 1.)continue;
00134 if(mip->tower_status[0] != 1)continue;
00135 if(mip->highest_neighbor > 2.)continue;
00136 if(TMath::Abs(pedsub) < 1.5*mip->tower_pedestal_rms[0])continue;
00137 if(mip->tower_id[0] != mip->tower_id_exit)continue;
00138 if(mip->vertexIndex > 0)continue;
00139 if(excluded_towers.find(mip->tower_id[0]) != excluded_towers.end()) continue;
00140
00141
00142 int index = mip->tower_id[0];
00143 double eta = helper->getEta(index);
00144 if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta;
00145 int etaindex = ((TMath::Nint(eta * 1000.0) + 25) / 50 + 19);
00146 ring_histo[etaindex]->Fill(pedsub);
00147
00148 }
00149 }
00150
00151 TFile* output_file = new TFile(skimfile,"RECREATE");
00152
00153 for(int k=0; k<nrings;k++) ring_histo[k]->Write();
00154 output_file->Close();
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 }
00224
00225 void drawTower(TH1* h, TF1* f, int id, CalibrationHelperFunctions* helper){
00226
00227 double peak = f->GetParameter(1);
00228 double histo_height = h->GetBinContent(h->GetMaximumBin());
00229 if(histo_height == 0) histo_height = 1.;
00230
00231
00232 h->SetXTitle("ADC/gev*sin(#theta)");
00233 h->Draw("esame");
00234
00235
00236 TLine *gaussian_peak = new TLine(peak,0.,peak,histo_height+15);
00237 gaussian_peak->SetLineColor(kGreen);
00238 gaussian_peak->SetLineWidth(2.0);
00239 gaussian_peak->Draw("same");
00240
00241
00242 char tower_title[100];
00243 float eta = (float)((id - 20) * 2 + 1)/40;
00244 sprintf(tower_title,"eta = %f",eta);
00245 TLatex title_latex;
00246 title_latex.SetTextSize(0.15);
00247 if(!helper->isGoodTower2006(id)) title_latex.SetTextColor(kRed);
00248 title_latex.DrawTextNDC(0.13,0.78,tower_title);
00249
00250
00251 TF1 *f2 = new TF1(tower_title,"gaus",0.,140.);
00252 f2->FixParameter(0,f->GetParameter(0));
00253 f2->FixParameter(1,f->GetParameter(1));
00254 f2->FixParameter(2,f->GetParameter(2));
00255 f2->SetLineWidth(0.6);
00256 f2->Draw("same");
00257 }
00258
00259
00260 double background_only_fit(double *x, double *par){
00261 double par3 = par[0]/1.5;
00262 double par4 = par[1] + 10.;
00263 double par5 = par[2] * 6.5;
00264
00265 double fitval = 0;
00266 if(par[2] != 0){
00267 double arg1 = (x[0]-par[1])/par[2];
00268 double arg2 = (x[0]-par4)/par5;
00269 fitval = par[0]*TMath::Exp(-0.5*arg1*arg1) + par3*TMath::Exp(-0.5*arg2*arg2);
00270 }
00271
00272 return fitval;
00273 }
00274
00275 double fit_function(double *x, double *par){
00276
00277
00278
00279
00280
00281
00282 double par3 = par[0] / par[3];
00283 double par6 = par3/1.5;
00284 double par7 = par[4] + 10.;
00285 double par8 = par[5] * 6.5;
00286
00287 double fitval = 0;
00288 if(par[2] != 0){
00289 double arg1 = (x[0]-par[1])/par[2];
00290 double arg2 = (x[0]-par[4])/par[5];
00291 double arg3 = (x[0]-par7)/par8;
00292 fitval = par[0]*TMath::Exp(-0.5*arg1*arg1) + par3*TMath::Exp(-0.5*arg2*arg2) + par6*TMath::Exp(-0.5*arg3*arg3);
00293 }
00294
00295 return fitval;
00296
00297
00298 }