/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/analyse/Microroc/Calibration/Calib_chip_microroc.cpp File Reference

#include <map>
#include "TKey.h"
#include <TROOT.h>
#include <TRint.h>
#include <TTree.h>
#include <TFile.h>
#include <TSystem.h>
#include <iostream>
#include <TF1.h>
#include <TGraph.h>
#include <sstream>
#include "Log.hh"
#include "MicroException.hh"
#include "root/MTRun.hh"
#include "root/MTDetector.hh"
#include "root/MTChamber.hh"
#include "root/MTChip.hh"
#include "root/MTEvent.hh"
#include "root/MTChannel.hh"
#include "root/MTHardroc2Chip.hh"

Include dependency graph for Calib_chip_microroc.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file Calib_chip_microroc.cpp.

00029                               {
00030 
00031   /*****************************************************************/
00032   /* ARGUMENTS TO THE PROGRAM **************************************/
00033   /* 1 - DIRECTORY OF THE ROOT FILE PRODUCED BY THE RECONSTRUCTION */
00034   /* 2 - NAME OF THE ROOT FILE *************************************/
00035   /* 3 - THRESHOLD THAT IS MOVED DURING THE CALIBRATION ************/
00036   /*    0 -> DAC_0 (LOW THRESHOLD) *********************************/
00037   /*    1 -> DAC_1 (MEDIUM THRESHOLD) ******************************/
00038   /*    2 -> DAC_2 (HIGH THRESHOLD) ********************************/
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 ;}


Generated on Mon Jan 7 13:17:02 2013 for MicromegasFramework by  doxygen 1.4.7