#include "tools/Log.hh"
#include "tools/Toolbox.hh"
#include "root/MTRun.hh"
#include "root/MTChannel.hh"
#include "root/MTEvent.hh"
#include "root/MTTrack.hh"
#include "MicroException.hh"
#include "TFile.h"
#include "TTree.h"
#include "TKey.h"
#include "TBranch.h"
#include "TRandom.h"
#include "TProfile.h"
#include "TH2I.h"
#include "TF1.h"
#include <sstream>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for makeHistosM3.cpp:
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 34 of file makeHistosM3.cpp.
00034 { 00035 00036 if ( argc != 3 ) 00037 { 00038 00039 cout<<endl; 00040 cout<<"**********************************************************************"<<endl; 00041 cout<<"Make histograms of hit position and time distribution for 3 thresholds"<<endl; 00042 cout<<"**********************************************************************"<<endl; 00043 cout<<endl; 00044 cout<<" Two arguments: PATH and ROOTFILE"<<endl; 00045 cout<<" e.g. -> ./bin/root/makePlotsM3 PATH ROOTFILE"<<endl; 00046 cout<<endl; 00047 cout<<"**********************************************************************"<<endl; 00048 cout<<endl; 00049 } 00050 00051 else 00052 { 00053 00054 TString directory = argv[1]; 00055 TString filename = argv[2]; 00056 00057 TString infile = directory + filename; 00058 00059 //convert boardid into slab number 00060 int slab[6] = {2,0,0,1,1,2}; 00061 00062 TString time,name,title; 00063 int xpos,ypos,digit,nchannel,chbid,hardid,channelid,boardid,chipid; 00064 Long64_t t,t0,t1,t2,t3,dt,tabs; 00065 00066 TH2I * hxy[50][3]; 00067 TH1I * hc_nhit[50][3]; 00068 TH1I * hdt[50][3]; 00069 00070 TH1I * hchb = new TH1I("hcbh",";chamber id",60,0,60); 00071 TH1I * hdt_all = new TH1I("hdt_all","Time to readout in all chambers;time (bcid)",100000,0,100000); 00072 00073 for (int i=0;i<50;i++) 00074 { 00075 for (int k=0;k<3;k++) 00076 { 00077 name = Form("hc_nhit_%i_dac%i",i+1,k); 00078 title = Form("Hit per channel in chb %i - thr %i;channel",i+1,k); 00079 hc_nhit[i][k] = new TH1I(name,title,9216,0,9216); 00080 00081 name = Form("hxy_%i_dac%i",i+1,k); 00082 title = Form("Hit distribution in chb %i - thr %i;channel",i+1,k); 00083 hxy[i][k] = new TH2I(name,title,96,0,96,96,0,96); 00084 00085 name = Form("hdt_%i_dac_%i",i+1,k); 00086 title = Form("Time to readout in chb %i - thr %i;time (bcid)",i+1,k); 00087 hdt[i][k] = new TH1I(name,title,1e4,0,1e6); 00088 } 00089 } 00090 00091 00092 00093 00094 00095 00096 TFile * tfile_input = new TFile(infile); 00097 cout<<endl; 00098 cout<<"Reading file : "<<infile<<endl; 00099 cout<<endl; 00100 00101 TIter nextkey(tfile_input->GetListOfKeys()); 00102 TKey *key; 00103 00104 int ntree = 0; 00105 00106 00107 00108 while (key = (TKey*)nextkey()) 00109 { 00110 TTree *tree = (TTree*)key->ReadObj(); 00111 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun"); 00112 00113 int nEvent = tree->GetEntries(); 00114 ntree++; 00115 cout<<" Tree "<<ntree<<" contains "<<nEvent<<" events"<<endl; 00116 00117 MTEvent *evt = new MTEvent(); 00118 00119 TBranch *branch= tree->GetBranch("MTEvent"); 00120 branch->SetAddress(&evt); 00121 00122 //nEvent = 100; 00123 for (int i=0;i<nEvent;i++) 00124 { 00125 if (i%10==0){cout<<"Progress: "<<i/1./nEvent*100<<" \r"<<flush;} 00126 tree->GetEntry(i); 00127 nchannel = evt->GetNchannel(); 00128 00129 //cout<<"Event "<<i<<" contains "<<nchannel<<" hits"<<endl; 00130 00131 /*Look in prototype*/ 00132 for (int j=0;j<nchannel;j++) 00133 { 00134 MTChannel* channel = (MTChannel*)evt->GetChannels()->UncheckedAt(j); 00135 chbid = channel->GetChamberId(); 00136 00137 hchb->Fill(chbid); 00138 00139 xpos = channel->GetX()*1e-4 + 48; 00140 ypos = channel->GetY()*1e-4 + 48; 00141 00142 digit = channel->GetDigitalValue(); 00143 hardid = channel->GetHardId(); 00144 chipid = channel->GetChipId(); 00145 00146 boardid = channel->GetBoardId()%6; 00147 boardid = slab[boardid]; 00148 00149 channelid = (chipid-1)*64 + hardid + 3072*boardid; 00150 00151 t2 = channel->GetBcId_Dif(); 00152 t3 = channel->GetBcId_Hit(); 00153 dt = t2 - t3; 00154 00155 if (digit==3) 00156 { 00157 for (int k=0;k<3;k++) 00158 { 00159 hc_nhit[chbid-1][k]->Fill(channelid); 00160 hxy[chbid-1][k]->Fill(xpos,ypos); 00161 hdt[chbid-1][k]->Fill(dt); 00162 } 00163 } 00164 else 00165 { 00166 if (digit==2) 00167 { 00168 for (int k=0;k<2;k++) 00169 { 00170 hc_nhit[chbid-1][k]->Fill(channelid); 00171 hxy[chbid-1][k]->Fill(xpos,ypos); 00172 hdt[chbid-1][k]->Fill(dt); 00173 } 00174 } 00175 else 00176 { 00177 if (digit==1) 00178 { 00179 hc_nhit[chbid-1][0]->Fill(channelid); 00180 hxy[chbid-1][0]->Fill(xpos,ypos); 00181 hdt[chbid-1][0]->Fill(dt); 00182 } 00183 } 00184 } 00185 hdt_all->Fill(dt); 00186 } 00187 } 00188 } 00189 00190 00191 00192 TString outfile = infile; 00193 00194 for (int k=0;k<5;k++){outfile.Chop();} 00195 00196 outfile += "_histos.root"; 00197 00198 TFile * tfile_output = new TFile(outfile,"RECREATE"); 00199 00200 cout<<endl; 00201 cout<<"Writing file : "<<outfile<<endl; 00202 cout<<endl; 00203 00204 00205 for (int i=0;i<50;i++) 00206 { 00207 for (int k=0;k<3;k++) 00208 { 00209 hc_nhit[i][k]->Write(); 00210 hxy[i][k]->Write(); 00211 hdt[i][k]->Write(); 00212 } 00213 } 00214 00215 00216 00217 00218 00219 } 00220 }