00001
00002 #include <map>
00003 #include "TKey.h"
00004 #include <TROOT.h>
00005 #include <TRint.h>
00006 #include <TKey.h>
00007 #include <TTree.h>
00008 #include <TFile.h>
00009 #include <TSystem.h>
00010 #include <iostream>
00011 #include <TF1.h>
00012 #include <TGraph.h>
00013 #include <sstream>
00014 #include "Log.hh"
00015
00016 #include "MicroException.hh"
00017
00018 #include "root/MTRun.hh"
00019 #include "root/MTDetector.hh"
00020 #include "root/MTChamber.hh"
00021 #include "root/MTChip.hh"
00022 #include "root/MTEvent.hh"
00023 #include "root/MTChannel.hh"
00024 #include "root/MTHardroc2Chip.hh"
00025
00026 using namespace std;
00027
00028
00029 int main(int argc, char**argv){
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 TString root_directory = argv[1];
00042 TString root_filename = argv[2];
00043 int dac = atoi(argv[3]);
00044
00045 bool display = 0;
00046
00047 TString root_file = root_directory + root_filename;
00048 TString scurve_file = root_directory + "scurve_" + root_filename;
00049
00050 cout<<"Wish to write "<<scurve_file<<endl;
00051
00052 int nbChannel = 0;
00053 float nbEvt = 0;
00054 int threshold = 0;
00055 int chipid = 0;
00056 int hardid = 0;
00057 int value = 0;
00058 int content = 0;
00059
00060 TH1I * hvalue = new TH1I("hvalue","",5,0,5);
00061 TH1I * hnpulse_threshold = new TH1I("hnpulse_threshold","",1024,0,1024);
00062
00063 TH1I * hscurve[64];
00064 TString name,title;
00065
00066 for (int j=0;j<64;j++){
00067
00068 name = Form("hscurve_%i",j);
00069 title = Form("SCurve from channel %i",j);
00070 hscurve[j] = new TH1I(name,title,1024,0,1024);}
00071
00072
00073
00074
00075
00076
00077 TFile f(root_file);
00078 TIter nextkey(f.GetListOfKeys());
00079 TKey *key;
00080
00081
00082 while (key = (TKey*)nextkey()) {
00083
00084 TTree *tree = (TTree*)key->ReadObj();
00085 MTRun* run = (MTRun*)tree->GetUserInfo()->FindObject("MTRun");
00086
00087 const MTChip& chip = run->GetOneChip();
00088 try{
00089 const MTHardroc2Chip &hr2Chip = dynamic_cast<const MTHardroc2Chip &> (chip);
00090 cout << "threshold dac 0:[" << hr2Chip.GetThresholdDac_0() << endl;
00091 cout << "threshold dac 1:[" << hr2Chip.GetThresholdDac_1() << endl;
00092 cout << "threshold dac 2:[" << hr2Chip.GetThresholdDac_2() << endl;
00093 if (dac==0){threshold = hr2Chip.GetThresholdDac_0();}
00094 if (dac==1){threshold = hr2Chip.GetThresholdDac_1();}
00095 if (dac==2){threshold = hr2Chip.GetThresholdDac_2();}
00096 }
00097 catch (...) {}
00098
00099
00100 MTEvent *evt = new MTEvent();
00101 TBranch *branch= tree->GetBranch("MTEvent");
00102 branch->SetAddress(&evt);
00103
00104 MTChannel* channel = NULL;
00105
00106 nbEvt = tree->GetEntries();
00107 cout<<"Number of events in the tree = "<<nbEvt<<endl;
00108
00109 hnpulse_threshold->SetBinContent(threshold+1,nbEvt);
00110
00111 for ( int evtNum = 0; evtNum < nbEvt ; evtNum++){
00112
00113 if (evtNum%1000 == 0){cout<<evtNum/nbEvt*100.<<" %"<<"\r"<<flush;}
00114
00115 tree->GetEntry(evtNum);
00116 nbChannel = evt->GetNchannel();
00117
00118 for(int i=0;i<nbChannel ;i++){
00119
00120 channel = (MTChannel*)evt->GetChannels()->UncheckedAt(i);
00121 chipid = channel->GetChipId();
00122 hardid = channel->GetHardId();
00123
00124 value = channel->GetDigitalValue();
00125 hvalue->Fill(value);
00126
00127 if (value==(dac+1)){
00128
00129 hscurve[hardid]->Fill(threshold);
00130
00131 if (display){
00132
00133 cout << "---- digital value:" << value <<endl;
00134 cout << "---- hard id:" << hardid <<endl;
00135 cout << "---- x:"<< channel->GetX() <<endl;
00136 cout << "---- y:" << channel->GetY() <<endl;
00137 cout << "---- chip id:" << chipid <<endl;}}}}}
00138
00139
00140
00141 cout<<endl;
00142
00143
00144
00145
00146
00147
00148
00149 TFile * tf = new TFile(scurve_file,"RECREATE");
00150 hvalue->Write();
00151 hnpulse_threshold->Write();
00152 for (int j=0;j<64;j++){
00153 hscurve[j]->Write();}
00154 tf->Close();
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 return 0 ;}
00167
00168
00169
00170