00001 #include <iostream>
00002 #include <fstream>
00003 #include <set>
00004 using namespace std;
00005
00006 void mip_histogram_maker(const char* file_list="", const char* skimfile="mipskimfile.root")
00007 {
00008 gROOT->Macro("LoadLogger.C");
00009 gROOT->Macro("loadMuDst.C");
00010 gSystem->Load("StTpcDb");
00011 gSystem->Load("StDaqLib");
00012 gSystem->Load("StDetectorDbMaker");
00013 gSystem->Load("St_db_Maker");
00014 gSystem->Load("StDbUtilities");
00015 gSystem->Load("StEmcRawMaker");
00016 gSystem->Load("StMcEvent");
00017 gSystem->Load("StMcEventMaker");
00018 gSystem->Load("StEmcSimulatorMaker");
00019 gSystem->Load("StEmcADCtoEMaker");
00020 gSystem->Load("StEpcMaker");
00021 gSystem->Load("StDbBroker");
00022 gSystem->Load("StEEmcUtil");
00023 gSystem->Load("StAssociationMaker");
00024
00025 gSystem->Load("StTriggerUtilities");
00026 gSystem->Load("StEmcOfflineCalibrationMaker");
00027
00028 const int ntowers=4800;
00029 const bool lookForSwaps=false;
00030
00031 cout<<"input filelist: "<<file_list<<endl;
00032 cout<<"histogram file: "<<skimfile<<endl;
00033
00034
00035 char file[300];
00036 TChain* calib_tree = new TChain("calibTree");
00037 ifstream filelist(file_list);
00038 TFile *test_file;
00039 while(1){
00040 filelist >> file;
00041 if(!filelist.good()) break;
00042 cout<<file<<endl;
00043 calib_tree->Add(file);
00044 }
00045
00046 StEmcOfflineCalibrationEvent* myEvent = new StEmcOfflineCalibrationEvent();
00047 calib_tree->SetBranchAddress("event_branch",&myEvent);
00048 StEmcOfflineCalibrationTrack* mip;
00049
00050
00051 TH2F* mapcheck = new TH2F("mapcheck","check mapping",4800,0.5,4800.5,4800,0.5,4800.5);
00052 mapcheck->SetXTitle("Track Projection ID");
00053 mapcheck->SetYTitle("Tower hit above 5 rms");
00054 TH1* mip_histo[ntowers];
00055 char name[100];
00056 for(int k=0; k<ntowers; k++){
00057 sprintf(name,"mip_histo_%i",k+1);
00058 mip_histo[k] = new TH1D(name,name,250,-50.5,199.5);
00059 }
00060
00061
00062 set<int> track_towers;
00063 set<int> excluded_towers;
00064 int ntracks = 0;
00065 int ngood = 0;
00066 unsigned int nentries = calib_tree->GetEntries();
00067 for(unsigned int i=0; i<nentries; i++){
00068 if(i%100000 == 0) cout<<"processing "<<i<<" of "<<nentries<<endl;
00069
00070 track_towers.clear();
00071 excluded_towers.clear();
00072
00073 calib_tree->GetEntry(i);
00074
00075
00076 if(TMath::Abs(myEvent->vz[0]) > 30.) continue;
00077
00078
00079 for(int j=0; j<myEvent->tracks->GetEntries(); j++){
00080 mip = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
00081 int id = mip->tower_id[0];
00082
00083 if(track_towers.find(id) != track_towers.end()){
00084 excluded_towers.insert(id);
00085 }
00086 else{
00087 track_towers.insert(id);
00088 }
00089 }
00090
00091
00092
00093
00094 for(int j=0; j<myEvent->tracks->GetEntries(); j++){
00095 mip = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
00096 ntracks++;
00097 double pedsub = mip->tower_adc[0] - mip->tower_pedestal[0];
00098
00099
00100 if(excluded_towers.find(mip->tower_id[0]) != excluded_towers.end()) continue;
00101 if(mip->p < 1.) continue;
00102
00103 if(mip->tower_id[0] != mip->tower_id_exit) continue;
00104
00105 for(int k = 0; k < 9; k++){
00106 if(mip->tower_adc[k] - mip->tower_pedestal[k] < 5*mip->tower_pedestal_rms[k])continue;
00107 mapcheck->Fill(mip->tower_id[0],mip->tower_id[k]);
00108 }
00109
00110 if(mip->highest_neighbor > 2.) continue;
00111 if(pedsub < 1.5*mip->tower_pedestal_rms[0])continue;
00112
00113
00114 int index = mip->tower_id[0];
00115 mip_histo[index-1]->Fill(pedsub);
00116 ngood++;
00117
00118 }
00119 }
00120
00121 cout<<"Added "<<ngood<<" tracks of "<<ntracks<<endl;
00122 TFile* output_file = new TFile(skimfile,"RECREATE");
00123 for(int k=0; k<ntowers; k++) mip_histo[k]->Write();
00124 mapcheck->Write();
00125 output_file->Close();
00126 }