StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mip_histogram_maker.C
1 #include <iostream>
2 #include <fstream>
3 #include <set>
4 using namespace std;
5 
6 void mip_histogram_maker(const char* file_list="", const char* skimfile="mipskimfile.root")
7 {
8  gROOT->Macro("LoadLogger.C");
9  gROOT->Macro("loadMuDst.C");
10  gSystem->Load("StTpcDb");
11  gSystem->Load("StDaqLib");
12  gSystem->Load("StDetectorDbMaker");
13  gSystem->Load("St_db_Maker");
14  gSystem->Load("StDbUtilities");
15  gSystem->Load("StEmcRawMaker");
16  gSystem->Load("StMcEvent");
17  gSystem->Load("StMcEventMaker");//***
18  gSystem->Load("StEmcSimulatorMaker");//***
19  gSystem->Load("StEmcADCtoEMaker");
20  gSystem->Load("StEpcMaker");
21  gSystem->Load("StDbBroker");
22  gSystem->Load("StEEmcUtil");
23  gSystem->Load("StAssociationMaker");
24  //gSystem->Load("StEmcTriggerMaker");
25  gSystem->Load("StTriggerUtilities");
26  gSystem->Load("StEmcOfflineCalibrationMaker");
27 
28  const int ntowers=4800;
29  const bool lookForSwaps=false;
30 
31  cout<<"input filelist: "<<file_list<<endl;
32  cout<<"histogram file: "<<skimfile<<endl;
33 
34  //chain all input files together
35  char file[300];
36  TChain* calib_tree = new TChain("calibTree");
37  ifstream filelist(file_list);
38  TFile *test_file;
39  while(1){
40  filelist >> file;
41  if(!filelist.good()) break;
42  cout<<file<<endl;
43  calib_tree->Add(file);
44  }
45 
47  calib_tree->SetBranchAddress("event_branch",&myEvent);
49 
50  //create the 4800 mip histograms
51  TH2F* mapcheck = new TH2F("mapcheck","check mapping",4800,0.5,4800.5,4800,0.5,4800.5);
52  mapcheck->SetXTitle("Track Projection ID");
53  mapcheck->SetYTitle("Tower hit above 5 rms");
54  TH1* mip_histo[ntowers];
55  char name[100];
56  for(int k=0; k<ntowers; k++){
57  sprintf(name,"mip_histo_%i",k+1);
58  mip_histo[k] = new TH1D(name,name,250,-50.5,199.5);
59  }
60 
61  //keep track of all hit towers and exclude any with >1 track/tower
62  set<int> track_towers;
63  set<int> excluded_towers;
64  int ntracks = 0;
65  int ngood = 0;
66  unsigned int nentries = calib_tree->GetEntries();
67  for(unsigned int i=0; i<nentries; i++){
68  if(i%100000 == 0) cout<<"processing "<<i<<" of "<<nentries<<endl;
69 
70  track_towers.clear();
71  excluded_towers.clear();
72 
73  calib_tree->GetEntry(i);
74 
75  //we're only working with events from vertexIndex==0
76  if(TMath::Abs(myEvent->vz[0]) > 30.) continue;
77 
78  //do a quick loop over tracks to get excluded towers
79  for(int j=0; j<myEvent->tracks->GetEntries(); j++){
80  mip = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
81  int id = mip->tower_id[0];
82 
83  if(track_towers.find(id) != track_towers.end()){
84  excluded_towers.insert(id);
85  }
86  else{
87  track_towers.insert(id);
88  }
89  }
90 
91  //select on runnumbers to look for stability
92  //if(myEvent->run < 7135000) continue;
93  //if(myEvent->tracks->GetEntries() > 0)cout<<"Processing event "<<i<<" with "<<myEvent->tracks->GetEntries()<<" tracks"<<endl;
94  for(int j=0; j<myEvent->tracks->GetEntries(); j++){
95  mip = (StEmcOfflineCalibrationTrack*)myEvent->tracks->At(j);
96  ntracks++;
97  double pedsub = mip->tower_adc[0] - mip->tower_pedestal[0];
98 
99  //cout<<mip->tower_id[0]<<" "<<mip->tower_id_exit<<" "<<pedsub<<" "<<mip->tower_pedestal_rms[0]<<" "<<mip->p<<" "<<mip->highest_neighbor<<" "<<mip->vertexIndex<<endl;
100  if(excluded_towers.find(mip->tower_id[0]) != excluded_towers.end()) continue;
101  if(mip->p < 1.) continue;
102  //if(mip->preshower_status[0] != 1) continue;
103  if(mip->tower_id[0] != mip->tower_id_exit) continue;
104 
105  for(int k = 0; k < 9; k++){
106  if(mip->tower_adc[k] - mip->tower_pedestal[k] < 5*mip->tower_pedestal_rms[k])continue;
107  mapcheck->Fill(mip->tower_id[0],mip->tower_id[k]);
108  }
109 
110  if(mip->highest_neighbor > 2.) continue;
111  if(pedsub < 1.5*mip->tower_pedestal_rms[0])continue;
112  //if(mip->vertexIndex > 0) continue;
113 
114  int index = mip->tower_id[0];
115  mip_histo[index-1]->Fill(pedsub);
116  ngood++;
117  //cout<<"track found in tower "<<index<<endl;
118  }
119  }
120 
121  cout<<"Added "<<ngood<<" tracks of "<<ntracks<<endl;
122  TFile* output_file = new TFile(skimfile,"RECREATE");
123  for(int k=0; k<ntowers; k++) mip_histo[k]->Write();
124  mapcheck->Write();
125  output_file->Close();
126 }