/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/root/BeamProfile.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1831 $ * @modifiedby $Author: lcdet $ * @lastmodified $Date: 2012-08-20 11:48:00 +0200 (Mon, 20 Aug 2012) $ */
00002 /* 
00003  * File:   BeamProfile.cpp
00004  * Author: jacquem
00005  * Created on May 6, 2010, 10:18 AM
00006  */
00007 
00008 
00009 #include "BeamProfile.hh"
00010 #include "root/MTEvent.hh"
00011 
00012 #include <iostream>
00013 #include <list>
00014 #include <stdlib.h>
00015 
00016 
00017 
00018 #include "TString.h"
00019 #include "TH2I.h"
00020 #include "TFile.h"
00021 #include "TTree.h"
00022 //#include "TPoint.h"
00023 #include "TBranch.h"
00024 #include "TKey.h"
00025 #include "TCanvas.h"
00026 #include "TApplication.h"
00027 
00028 
00029 #include <TGClient.h>
00030 #include <TGListBox.h>
00031 #include <TPaveLabel.h>
00032 #include <TGeoManager.h>
00033 #include <TGeoMatrix.h>
00034 
00035 
00036 
00037 
00038 
00039 # include <TStyle.h>
00040 #include "root/MTChipSoftId.hh"
00041 #include "root/MTDifSoftId.hh"
00042 #include "geometry/Detector.hh"
00043 #include "geometry/Chamber.hh"
00044 #include "geometry/Chip.hh"
00045 #include "geometry/Channel.hh"
00046 #include "geometry/Dif.hh"
00047 #include "geometry/Board.hh"
00048 #include "geometry/Chip.hh"
00049 #include "mTypes.h"
00050 #include "tools/Toolbox.hh"
00051 #include "tools/MicroException.hh"
00052 #include "math.h"
00053 
00054 
00055 
00056 using namespace std;
00057 
00058 BeamProfile::BeamProfile() :timeCutMax(0xffffffff) , timeCutMin(0),
00059                                                         chamberId(-1),difId(-1),boardId(-1),chipId(-1),
00060                                                         showRunInfo(false) ,
00061                                                         maxHistogram(10),
00062                                                         showXYDistribution(false), showDeltaDistribution(false),
00063                                                         minDeltaTValue(0xffffffff),maxDeltaTValue(0),
00064                                                         minHitPerChannelValue(0),maxHitPerChannelValue(0),
00065                                                         detector(NULL),showHotChip(false),
00066                                                         showHotChamber(false), nbhit(0) , adc(0),
00067                                                         analogCut(false), timeCut(false),
00068                                         maxHitPerChannel(0),minHitPerChannel(0xffff),
00069                                         maxHitPerChip(0),minHitPerChip(0xffff),
00070                                                         showHitPerChipDistribution(false), showHitPerChannelDistribution(false){
00071 }
00072 //---------------------------------------------//
00073 //                                             //
00074 //---------------------------------------------//
00075 
00076 
00077 BeamProfile::BeamProfile(int argc, char **argv): timeCutMax(0xffffffff) , timeCutMin(0),
00078                                                         chamberId(-1),difId(-1),boardId(-1),chipId(-1),
00079                                                         showRunInfo(false) ,
00080                                                         maxHistogram(10),
00081                                                         showXYDistribution(false), showDeltaDistribution(false),
00082                                                         minDeltaTValue(0xffffffff),maxDeltaTValue(0),
00083                                                         minHitPerChannelValue(0),maxHitPerChannelValue(0),
00084                                                         detector(NULL),showHotChip(false),
00085                                                         showHotChamber(false), nbhit(0) , adc(0),
00086                                                         analogCut(false), timeCut(false),
00087                                         maxHitPerChannel(0),minHitPerChannel(0xffff),
00088                                         maxHitPerChip(0),minHitPerChip(0xffff),
00089                                                         showHitPerChipDistribution(false), showHitPerChannelDistribution(false)
00090 {
00091         nbArgs =  argc;
00092         args = argv;
00093   this->parseOptions();
00094 
00095         //float min = 1.27589e12;
00096         //float max = 1.27591e12;
00097         float min = 200000000;
00098         float max = 300000000;
00099 
00100         chamberHotHist =  new TH1I("hot_chamber", "hot chamber distribution", 11,0,10);
00101 
00102 }
00103 
00104 /*---------------------------------------------*/
00105 //                                             //
00106 //---------------------------------------------//
00107 BeamProfile::BeamProfile(const BeamProfile& orig) {
00108 }
00109 
00110 /*---------------------------------------------*/
00111 //                                             //
00112 //---------------------------------------------//
00113 BeamProfile::~BeamProfile() {
00114 }
00115 
00116 /*---------------------------------------------*/
00117 //                                             //
00118 //---------------------------------------------//
00119 void BeamProfile::SetDetector( Detector* det)
00120 {
00121   detector = det;
00122 }
00123 /*---------------------------------------------*/
00124 //                                             //
00125 //---------------------------------------------//
00126 void BeamProfile::askOptions()
00127 {
00128   string answer;
00129       
00130 
00131   //---------------------------)
00132     if ( nbArgs == 2  )
00133     {
00134         fileName = args[1];
00135     }
00136     else
00137     {
00138         cout << " root file name :" ;
00139         cin >> answer ;
00140         cin.ignore(100, '\n');
00141         fileName = answer;
00142     }
00143 
00144     cout << endl;
00145 
00146   //---------------------------)
00147   cout << "xml file name for geometry (delault null): " ; getline(cin, answer);
00148   if (!answer.empty()) { istringstream istr(answer); istr >> xmlFileName; }
00149 
00150 
00151   //---------------------------)
00152     cout << "cut on Hardroc[bcid_dif - bcid_hit] value y/(n)? " ; getline(cin, answer);
00153     if (!answer.empty()) {
00154         istringstream istr(answer);
00155         istr >> answer;
00156     }
00157     if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00158     {
00159         timeCut = true;
00160 
00161         timeCutMin = 0;
00162         cout << "min cut delatT (0)" ; getline(cin, answer);
00163         if (!answer.empty()) { istringstream istr(answer); istr >> answer; timeCutMin = atoi(answer.c_str()); }
00164 
00165         timeCutMax = 15;
00166         cout << "min cut delatT (15)" ; getline(cin, answer);
00167         if (!answer.empty()) { istringstream istr(answer); istr >> answer; timeCutMax = atoi(answer.c_str()); }
00168     }
00169 
00170 
00171 
00172   //---------------------------)
00173   cout << "cut on Gassiplex analog value ? y/(n): " ; getline(cin, answer);
00174   if (!answer.empty()) {
00175                     istringstream istr(answer);
00176                     istr >> answer;
00177                     if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00178                     {
00179                                                     analogCut = true;
00180 
00181                         analogCutMin = 0;
00182           cout << "min analog value (0): " ; getline(cin, answer);
00183           if (!answer.empty()) { istringstream istr(answer); istr >> answer; analogCutMin = atoi(answer.c_str()); }
00184 
00185                         analogCutMax = 1024;
00186           cout << "max analog value (1024): " ; getline(cin, answer);
00187           if (!answer.empty()) { istringstream istr(answer); istr >> answer; analogCutMax = atoi(answer.c_str()); }
00188                     }
00189 
00190                 }
00191                 
00192 
00193          //---------------------------)
00194     cout << "Print run informations ? y/(n): " ; getline(cin, answer);
00195     if (!answer.empty())
00196     {
00197      
00198         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00199         {
00200             this->showRunInfo = true;
00201         }
00202     }
00203     
00204 
00205    //---------------------------
00206    cout << "Show xy distribution ? y/(n) : " ; getline(cin, answer);
00207    if (!answer.empty())
00208                         { istringstream istr(answer); istr >> answer; 
00209             
00210                             if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00211                             {
00212                                             this->showXYDistribution = true;
00213                         }
00214                         }
00215         
00216     //---------------------------
00217     cout << "show delta T ( bcid_dif - bcid_hit ) distribution by chip ? y/(n) : " ; getline(cin, answer);
00218     if (!answer.empty())
00219     {
00220         istringstream istr(answer); istr >> answer;
00221         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00222         {
00223             this->showDeltaDistribution = true;
00224         }
00225     }
00226     
00227     //---------------------------
00228     cout << "show hot chambers ? y/(n) : " ; getline(cin, answer);
00229     if (!answer.empty())
00230     {
00231         istringstream istr(answer); istr >> answer;
00232         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00233         {
00234             this->showHotChamber = true;
00235 
00236             this->adc = 0;
00237             cout << "min adc value (0): " ; getline(cin, answer);
00238             if (!answer.empty()) { istringstream istr(answer); istr >> answer;  this->adc = atoi(answer.c_str()); }
00239 
00240             this->nbhit = 2;
00241             cout << "hits number to consider chamber as hot. Value should be [1 <-> nbHit] (defalut 2): " ; getline(cin, answer);
00242             if (!answer.empty()) { istringstream istr(answer); istr >> answer; this->nbhit = atoi(answer.c_str()); }
00243         }
00244     }
00245    //---------------------------
00246     cout << "show hot chip ? y/(n) : " ; getline(cin, answer);
00247     if (!answer.empty())
00248     {
00249         istringstream istr(answer); istr >> answer;
00250         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00251         {
00252         this->showHotChip = true;
00253         }
00254     }
00255                 
00256 
00257 
00258 
00259    //---------------------------
00260     cout << "show hit per Chip distribution for a chamber/Dif ? y/(n) : " ; getline(cin, answer);
00261     if (!answer.empty())
00262     {
00263         istringstream istr(answer); istr >> answer;
00264         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00265         {
00266             this->showHitPerChipDistribution = true;
00267         }
00268     }
00269                         
00270 
00271    //---------------------------
00272     cout << "show hit per Channel distribution for a Chip ? y/(n) : " ; getline(cin, answer);
00273     if (!answer.empty())
00274     {
00275         istringstream istr(answer); istr >> answer;
00276         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00277         {
00278             this->showHitPerChannelDistribution = true;
00279         }
00280     }
00281                 
00282 
00283     //---------------------------
00284     cout << "Filter histogram for a chamber id ?  y/(n)" ; getline(cin, answer);
00285     if (!answer.empty())
00286     {
00287         istringstream istr(answer); istr >> answer;
00288         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00289         {
00290             this->chamberId = -1;
00291             cout << "chamber id (-1): " ; getline(cin, answer);
00292             if (!answer.empty()) { istringstream istr(answer); istr >> answer;  this->chamberId = atoi(answer.c_str()); }
00293             cout << "chamber id[" <<  this->chamberId << "]" << endl;
00294         }
00295     }
00296   
00297       //---------------------------
00298     cout << "Filter histogram for a Dif id ?  y/(n)" ; getline(cin, answer);
00299     if (!answer.empty())
00300     {
00301         istringstream istr(answer); istr >> answer; 
00302         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00303         {
00304             this->difId = -1;
00305             cout << "dif id (-1): " ; getline(cin, answer);
00306             if (!answer.empty()) { istringstream istr(answer); istr >> answer;  this->difId = atoi(answer.c_str()); }
00307           }
00308     }
00309       //---------------------------
00310     cout << "Filter histogram for a ASU id ?  y/(n)" ; getline(cin, answer);
00311     if (!answer.empty())
00312     {
00313         istringstream istr(answer); istr >> answer;
00314         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00315         {
00316             this->boardId = -1;
00317             cout << "ASU id (-1): " ; getline(cin, answer);
00318             if (!answer.empty()) { istringstream istr(answer); istr >> answer;  this->boardId = atoi(answer.c_str()); }
00319           }
00320     }
00321       //---------------------------
00322     cout << "Filter histogram for a chip id ?  y/(n)" ; getline(cin, answer);
00323     if (!answer.empty())
00324     {
00325         istringstream istr(answer); istr >> answer; 
00326         if ( answer.compare("y") == 0 || answer.compare("Y") == 0)
00327         {
00328             this->chipId = -1;
00329             cout << "chip id (-1): " ; getline(cin, answer);
00330             if (!answer.empty()) { istringstream istr(answer); istr >> answer;  this->chipId = atoi(answer.c_str()); }
00331           }
00332     }
00333     //---------------------------
00334  
00335     cout << "Maximum histogram number to display ?  (10): " ; getline(cin, answer);
00336     if (!answer.empty()) { istringstream istr(answer); istr >> answer;  this->maxHistogram = atoi(answer.c_str()); }
00337   
00338 }
00339 /*---------------------------------------------*/
00340 //                                             //
00341 //---------------------------------------------//
00342 void BeamProfile::parseOptions()
00343 {
00344     if ( (nbArgs == 2 &&  strcmp(args[1],  "-h") != 0 ) || nbArgs == 1)
00345     {
00346         askOptions();
00347         return;
00348     }
00349 
00350     fileName = args[1];
00351 
00352     for ( int index = 1 ; index < nbArgs  ; index++ )
00353     {
00354         if ( strcmp(args[index],  "-h") == 0 )
00355         {
00356             cout << endl << endl << "-------------- beamProfile HELP --------------" << endl ;
00357             cout << endl << "---Files---" << endl;
00358             cout << "usage: beamProfile   [root file Name]" << endl << endl;
00359             cout << "-xml [xml file Name]" << endl;
00360 
00361 
00362             cout << endl << "---Shows option---" << endl;
00363             cout << "-maxHisto [set max number of  histograms ( default is 10)" << endl;;
00364             cout << "-r         : show Run info ( date, name, chip config ... )" << endl ;
00365             cout << "-deltaT    : show delta T ( bcid_dif - bcid_hit ) distribution by chip" << endl;
00366             cout << "-xy        : show XY distribution by chamber" << endl;
00367             cout << "-hitChip   : show hit per Chip distribution for a chamber/Dif" << endl;
00368             cout << "-hitChannel: show hit per Channel distribution for a Chip" << endl;
00369             cout << "-hotChamber: show hot chambers" << endl;
00370             cout << "          -adc [value]   : set min adc value" << endl;
00371             cout << "          -nbhit [value] : set nb hit to consider chamber as hot. Value should be [ 1 - nbHit ]" << endl;
00372             cout << "-hotChip   : Print per chamber chip within maximun hits." << endl;
00373             cout << "-showAll   : show all histograms" << endl;
00374             cout << endl << "---Cuts---" << endl;
00375             cout << "-cutTime [min value] [max value]: cut on Hardroc[bcid_dif - bcid_hit] value ->  min < bcid_dif - bcid_hit < max." << endl;
00376             cout << "-cutAnalog [min value] [max value]: cut on Gassiplex analog value." << endl;
00377             cout << endl << "---Filters---" << endl;
00378             cout << "-chamber [ chamber id]     : only display histogram for this chamber" << endl;
00379             cout << "-dif     [ dif id]         : only display histogram for this dif"<< endl;
00380             cout << "-asu     [ asu (board) id] : only display histogram for this ASU ( board )"<< endl;
00381             cout << "-chip    [ chip id]        : only display histogram for this chip"<< endl;
00382             cout <<  endl << "-------------------------------------------------" << endl;
00383             exit(0);
00384         }
00385       //---------------------------
00386         if ( strcmp(args[index],  "-xml") == 0  && nbArgs > index+1 )
00387         {
00388             index++;
00389             xmlFileName = args[index];
00390         }
00391       //---------------------------
00392         else if ( strcmp(args[index],  "-cutTime") == 0 && nbArgs > index+1 )
00393         {
00394             index++;
00395             timeCut  = true;
00396             if ( nbArgs > index  )
00397             {
00398                 timeCutMin = atoi(args[index]);
00399                 index++;
00400             }
00401             if ( nbArgs > index  )
00402             {
00403                 timeCutMax = atoi(args[index]);
00404             }
00405         }
00406         //---------------------------
00407         else if ( strcmp(args[index],  "-cutAnalog") == 0 && nbArgs > index+1 )
00408         {
00409             index++;
00410             analogCut  = true;
00411             if ( nbArgs > index  )
00412             {
00413                 analogCutMin = atoi(args[index]);
00414                 index++;
00415             }
00416             if ( nbArgs > index  )
00417             {
00418                 analogCutMax = atoi(args[index]);
00419             }
00420         }
00421 
00422 
00423 
00424         //---------------------------
00425         else if ( strcmp(args[index],  "-r") == 0 )
00426         {
00427             this->showRunInfo = true;
00428         }
00429   //---------------------------
00430         else if ( strcmp(args[index],  "-showAll") == 0 )
00431         {
00432                 this->showHitPerChipDistribution = true;
00433                 this->showXYDistribution = true;
00434                 this->showDeltaDistribution = true;
00435                 this->showHitPerChannelDistribution = true;
00436                 this->showHotChamber = true;
00437                 this->showHotChip = true;
00438         }
00439   //---------------------------
00440         else if ( strcmp(args[index],  "-xy") == 0 )
00441         {
00442                 this->showXYDistribution = true;
00443         }
00444   //---------------------------
00445         else if ( strcmp(args[index],  "-deltaT") == 0 )
00446         {
00447                 this->showDeltaDistribution = true;
00448         }
00449 
00450   //---------------------------
00451         else if ( strcmp(args[index],  "-hotChamber") == 0 )
00452         {
00453                 this->showHotChamber = true;
00454         }
00455 
00456   //---------------------------
00457         else if ( strcmp(args[index],  "-adc") == 0 )
00458         {
00459                  if ( nbArgs > index+1  )
00460                  {
00461                         index++;
00462                     this->adc = atoi(args[index]);
00463                  }
00464         }
00465   //---------------------------
00466         else if ( strcmp(args[index],  "-nbhit") == 0 )
00467         {
00468                  if ( nbArgs > index+1  )
00469                  {
00470                         index++;
00471                     this->nbhit = atoi(args[index]);
00472                  }
00473         }
00474   //---------------------------
00475         else if ( strcmp(args[index],  "-hotChip") == 0 )
00476         {
00477                 this->showHotChip = true;
00478         }
00479   //---------------------------
00480         else if ( strcmp(args[index],  "-hitChip") == 0 )
00481         {
00482                 this->showHitPerChipDistribution = true;
00483         }
00484   //---------------------------
00485         else if ( strcmp(args[index],  "-hitChannel") == 0 )
00486         {
00487                 this->showHitPerChannelDistribution = true;
00488         }
00489   //---------------------------
00490         else if ( strcmp(args[index],  "-chamber") == 0 )
00491         {
00492                  if ( nbArgs > index+1  )
00493                  {
00494                         index++;
00495           this->chamberId = atoi(args[index]);
00496                  }
00497         }
00498   //---------------------------
00499         else if ( strcmp(args[index],  "-dif") == 0 )
00500         {
00501                  if ( nbArgs > index+1  )
00502                  {
00503                         index++;
00504           this->difId = atoi(args[index]);
00505                  }
00506         }
00507   //---------------------------
00508         else if ( strcmp(args[index],  "-asu") == 0 ||  strcmp(args[index],  "-board") == 0)
00509         {
00510                  if ( nbArgs > index+1  )
00511                  {
00512                         index++;
00513           this->boardId = atoi(args[index]);
00514                  }
00515         }
00516   //---------------------------
00517         else if ( strcmp(args[index],  "-chip") == 0 )
00518         {
00519                  if ( nbArgs > index+1  )
00520                  {
00521                         index++;
00522           this->chipId = atoi(args[index]);
00523                 }
00524         }
00525       //---------------------------
00526         else if ( strcmp(args[index],  "-maxHisto") == 0 )
00527         {
00528             if ( nbArgs > index+1  )
00529             {
00530                 index++;
00531                 this->maxHistogram = atoi(args[index]);
00532             }
00533         }
00534 
00535       //---------------------------
00536         else if(index > 1 )
00537         {
00538             cout << "Unknown option[" << args[index] << "]" <<endl;
00539             exit(-1);
00540         }
00541     }
00542 }
00543 
00544 
00545 
00546 /*---------------------------------------------*/
00547 //                                             //
00548 //---------------------------------------------//
00549 int BeamProfile::getNbHist()
00550 {
00551                 //return xyKeyChamber.size() + hitPerChipKeyChamberDif.size() +  hitPerChannelKeyChip.size() + deltaTKeyChip.size() ;
00552                 int result =  xyKeyChamber.size() + hitPerChipKeyChamberDifMap.size() +  hitPerChannelKeyChipMap.size() + deltaTKeyChipMap.size() ;
00553                 return result;
00554 }
00555 
00556 /*---------------------------------------------*/
00557 //                                             //
00558 // return true if channel is filtered and do not have to be show
00559 //---------------------------------------------//
00560 bool BeamProfile::filterOnId(const MTChannel &channel)
00561 {
00562 
00563     //cout << " filter ChipId()[" << this->getChipId() <<"]" << endl;
00564 
00565 
00566     if ( (  (this->getChipId()    != channel.GetChipId())   && this->getChipId()    != -1) ||
00567             (this->getChamberId() != channel.GetChamberId() && this->getChamberId() != -1 )||
00568             (this->getDifId()     != channel.GetDifId()     && this->getDifId()     != -1 )||
00569             (this->getBoardId()   != channel.GetBoardId()   && this->getBoardId()   != -1 ))
00570 
00571     {
00572         return true;
00573     }
00574     return false;
00575 }
00576 
00577 /*---------------------------------------------*/
00578 //                                             //
00579 // return true if channel is filtered and do not have to be show
00580 //---------------------------------------------//
00581 bool BeamProfile::filterOnCut(const MTChannel &channel)
00582 {
00583 
00584 // Cut on time
00585     if ( timeCut   )
00586     {
00587               int dt = (channel.GetBcIdDif()-channel.GetBcIdHit());
00588         if ( (dt<timeCutMin || dt>timeCutMax) && dt!= 0) { return true; }
00589     }
00590 
00591 
00592                 if ( analogCut )
00593                 {
00594                         if ( ( channel.GetAnalogValue() > analogCutMax || channel.GetAnalogValue()  < analogCutMin )  &&   channel.GetAnalogValue() != 0  )  // gassiplex cut on analog value
00595         {
00596             return true;
00597         }
00598                 }
00599 
00600         return false;
00601 }
00602 /*---------------------------------------------*/
00603 //                                             //
00604 //---------------------------------------------//
00605 
00606 bool BeamProfile::FillHotChip( const MTChannel &channel)
00607 {
00608     if ( ! showHotChip ) { return false ; }
00609     if (  filterOnCut(channel)) { return false; }
00610 
00611     const MTChipSoftId& chipSoftId = (MTChipSoftId)(channel.GetSoftId());
00612     const string key = chipSoftId.toString();
00613     const ui16 chamberId = channel.GetChamberId();
00614 
00615     map<string,int>   *nbHitPerChip  = nbHitPerChipPerChamber[chamberId];
00616     if (  nbHitPerChip == NULL )
00617     {
00618         nbHitPerChip = new map<string,int>();
00619         nbHitPerChipPerChamber[chamberId] = nbHitPerChip;
00620     }
00621 
00622     if (nbHitPerChip->find(key) == nbHitPerChip->end())  { (*nbHitPerChip)[key] = 0; }
00623 
00624     (*nbHitPerChip)[key]= (*nbHitPerChip)[key]+channel.GetAnalogValue()+ channel.GetDigitalValue();
00625     return true;
00626 }
00627 
00628 /*---------------------------------------------*/
00629 //                                             //
00630 //---------------------------------------------//
00631 
00632 void BeamProfile::PrintHotChip()const
00633 {
00634                 if ( ! showHotChip ) { return ; }
00635 
00636                 map<ui16,string> hotChip;
00637                 map<ui16,ui32>  hotChipValue;
00638 
00639     for ( map<ui16,map<string, int>* >::const_iterator iterChamber = nbHitPerChipPerChamber.begin(); iterChamber != nbHitPerChipPerChamber.end(); iterChamber++)
00640                 {
00641               map<string,int> *nbHitPerChip = (*iterChamber).second;
00642                                 ui16 chamberId =(*iterChamber).first;
00643 
00644         for ( std::map<string, int>::const_iterator iter = nbHitPerChip->begin(); iter != nbHitPerChip->end(); iter++)
00645         {
00646                                                 if (hotChipValue.find(chamberId) == hotChipValue.end())  { (hotChipValue)[chamberId] = 0; }
00647 
00648                                     if ( (*iter).second  > hotChipValue[chamberId] )
00649                                     {
00650                (hotChip)[chamberId] = (*iter).first;
00651                                                          hotChipValue[chamberId] = (*iter).second ;
00652                                         }
00653                     }
00654                 }
00655                 //return *hotChip;
00656 
00657     for ( std::map<ui16, string>::const_iterator iter = hotChip.begin(); iter != hotChip.end(); iter++)
00658     {
00659         cout << "Hot chip for chamber:" << (*iter).first << ", is :" << (*iter).second << endl;
00660     }
00661 
00662 }
00663 /*---------------------------------------------*/
00664 //                                             //
00665 //---------------------------------------------//
00666 bool BeamProfile::FillXyDist( const MTChannel &channel)
00667 {
00668 //  if (channel.GetChamberId() >= 41 && channel.GetChamberId() <= 50)
00669 //{
00670   // filter on show and filter options
00671   if ( ! this->getShowXYDistribution() || filterOnId(channel) || filterOnCut(channel)  )
00672   {
00673   return false; 
00674   }
00675 
00676 
00677 
00678   // Fill xy distribution histogram
00679   TH2I* hist = this->xyKeyChamber[channel.GetChamberId()];
00680   if ( hist == NULL )
00681   {// First hit create historgram
00682     // create and configure a xy distribution histogram per chamber
00683     string xyname("hxy_");
00684     Toolbox::addIntToString(xyname,channel.GetChamberId());
00685 
00686     string  xytitle("XY distribution of hits in chamber ");
00687     Toolbox::addIntToString(xytitle,channel.GetChamberId());
00688 
00689     if  (getNbHist() <= maxHistogram)
00690     {
00691       //TPoint minPoint(-100,-100);
00692       //TPoint maxPoint(100,100);
00693       float leftBottomX = -100000.;
00694       float leftBottomY = -100000.;
00695       float rightUpperX = 100000.;
00696       float rightUpperY = 100000.;
00697 
00698       if ( detector != NULL)
00699       {
00700         const Chamber& chamber  =       detector->getChamberById(channel.GetChamberId());
00701         rightUpperX = chamber.getRightUpperX();
00702         rightUpperY = chamber.getRightUpperY();
00703         leftBottomX = chamber.getLeftBottomX();
00704         leftBottomY = chamber.getLeftBottomY();
00705 
00706       }
00707 
00708       Int_t     nbinx = (rightUpperX - leftBottomX) / 10000;
00709       Int_t     nbiny = (rightUpperY - leftBottomY) / 10000 ;
00710 
00711 
00712       // create histogram
00713       TH2I* xy = new TH2I(xyname.c_str(),xytitle.c_str(),nbiny,leftBottomY,rightUpperY,nbinx,leftBottomX,rightUpperX);
00714 
00715 
00716       //TH2I* xy = new TH2I(xyname.c_str(),xytitle.c_str(),48,0,48,32,0,32);
00717       //(const char* name, const char* title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup)
00718       xy->SetXTitle("y");
00719       xy->SetYTitle("x");
00720       cout << "Create XY dist for " << xytitle << endl;
00721 
00722       // store it to the map
00723       xyKeyChamber[channel.GetChamberId()] = xy;
00724     }
00725     else
00726     {
00727       return false;
00728     }
00729   }
00730   hist = xyKeyChamber[channel.GetChamberId()];
00731   hist->Fill(channel.GetY(),channel.GetX(),channel.GetAnalogValue()+channel.GetDigitalValue());
00732   return true;
00733 
00734 //}
00735 return true;
00736 }
00737 
00738 /*---------------------------------------------*/
00739 //                                             //
00740 //---------------------------------------------//
00741 void BeamProfile::DrawXyDist()
00742 {
00743 
00744     if ( this->xyKeyChamber.size() > 0 )
00745     {
00746     // Draw XY distribution
00747         TCanvas * cxy = new TCanvas("cxy","",10,10,1200,300);
00748         ui16 nbChambers =  xyKeyChamber.size();
00749         if ( nbChambers>1) cxy->Divide((nbChambers+1)/2,2);
00750 
00751         ui16 cur = 1;
00752         for ( std::map<ui16, TH2I*>::const_iterator iter = xyKeyChamber.begin(); iter != xyKeyChamber.end(); iter++)
00753         {
00754             cxy->cd(cur);
00755             cur++;
00756             if ((*iter).second )
00757             {
00758                  if ((*iter).second->GetSize() > 0 )
00759                        {
00760                            (*iter).second->Draw("zcol");
00761                        }
00762                                     }
00763 
00764                     }
00765     }
00766 }
00767 
00768 /*---------------------------------------------*/
00769 //                     2                        //
00770 //---------------------------------------------//
00771 
00772 bool BeamProfile::FillHitPerChipDist(const  MTChannel &channel)
00773 {
00774                 if ( ! this->showHitPerChipDistribution  || filterOnId(channel ) ||  filterOnCut(channel) ) { return false; }
00775 
00776 
00777                 // Key is Chip string softId
00778                 const DifSoftId &difSoftId = (const DifSoftId&)(channel.GetSoftId());
00779 
00780 
00781 
00782                 string key = difSoftId.toString();
00783 
00784     map<Int_t ,Int_t> *hist =   this->hitPerChipKeyChamberDifMap[key];
00785 
00786                 // If map for this chip does not exist, create it
00787                 if ( hist == NULL)
00788                 {
00789                         // Create new map only if maxHistogram is not reach
00790           if ( getNbHist() <= maxHistogram)
00791                   {
00792                       // create histogram
00793                             map<Int_t ,Int_t> *dic = new map<Int_t ,Int_t>();
00794                                         // store new map in hit per channel map which contains one hit per channel map per Chip
00795                       hitPerChipKeyChamberDifMap[key] = dic;
00796                                                                                                                         cout << "key[" << key << "]" << endl;
00797                         }
00798                         else
00799                         {
00800                             cout << "Warning could not create histogram for key ( chamber and Dif )[ " << key << " ]because max histogram number is reach ( use -maxHisto to change value." << endl;
00801                             return false;
00802                         }
00803                 }
00804 
00805                 UInt_t chipID =  channel.GetChipId();
00806                 // Store min and max deltaT value
00807                 if ( detector != NULL)
00808                 {
00809                     const Chamber& chamber      =       detector->getChamberById(channel.GetChamberId());
00810                           const BoardMap_t  &boards = chamber.getBoards();
00811                                 const Board* board = boards.find(channel.GetBoardId())->second;
00812                                 if ( minHitPerChipValue.find(key) == minHitPerChipValue.end())   {      minHitPerChipValue[key] = 0xffff; }
00813                                 if ( maxHitPerChipValue.find(key) == maxHitPerChipValue.end())   {      maxHitPerChipValue[key] = 0; }
00814                                 minHitPerChipValue[key] = board->getMinChipId();
00815                                 maxHitPerChipValue[key]= board->getMaxChipId();
00816                 }
00817                 else
00818                 {
00819                     if ( chipID < minHitPerChipValue[key] )  { minHitPerChipValue[key] = chipID; }
00820                     if ( chipID > maxHitPerChipValue[key] )  { maxHitPerChipValue[key] = chipID; }
00821                 }
00822                 // Get Map gor thus chip
00823                 map<Int_t ,Int_t> &tmp =  *hitPerChipKeyChamberDifMap[key];
00824                 tmp[chipID] = tmp[chipID]+1;
00825   if ( tmp[chipID] > maxHitPerChip ) { maxHitPerChip = tmp[chipID];}
00826   if ( tmp[chipID] < minHitPerChip ) { minHitPerChip = tmp[chipID];}
00827 
00828         return true;
00829 }
00830 
00831 
00832 /*---------------------------------------------*/
00833 //                                             //
00834 //---------------------------------------------//
00835 void BeamProfile::DrawHitPerChipDist()
00836 {
00837 
00838         if (   this->showHitPerChipDistribution  )
00839         {
00840 // Draw Delta_T distribution
00841             int cur = 0;
00842             for ( map<string,std::map<Int_t ,Int_t>* >::const_iterator iter = hitPerChipKeyChamberDifMap.begin(); iter != hitPerChipKeyChamberDifMap.end(); iter++)
00843             {
00844                             cur++;
00845                             if ((*iter).second )
00846                             {
00847                                             //Canvas
00848                                             string c_title("TCancasHitPerChip");
00849                                             Toolbox::addIntToString(c_title,cur);
00850                                             TCanvas * canvas = new TCanvas(c_title.c_str(),"",10,10,1200,300);
00851 
00852                                                 // Histogram configuration
00853                                             string name("HitPerChip_ T_");
00854                                             string title("Hit per Chip distribution for ");
00855                                             title+=(*iter).first;
00856                                             //Toolbox::addIntToString(title,    (*iter).first);
00857                                             Toolbox::addIntToString(name,cur);
00858 
00859                                             // Compute bining
00860                                             string key = (*iter).first;
00861                                             UInt_t nbBin =  maxHitPerChipValue[key] - minHitPerChipValue[key];
00862                                             TH1I *newHist = new TH1I(name.c_str(),title.c_str(), nbBin,  minHitPerChipValue[key]  ,maxHitPerChipValue[key] );
00863 
00864                                             // Get all hit Per chip  entry and fill new Histogram with pre conputed weight
00865                                             map<Int_t ,Int_t>   content = *((*iter).second);
00866                                             for ( map<Int_t ,Int_t>::const_iterator iterC = content.begin(); iterC != content.end(); iterC++)
00867                                             {
00868                                                     Int_t val = (*iterC).second;
00869                                                     newHist->Fill((*iterC).first,val);
00870                                             }
00871                                             newHist->Draw();
00872                             }
00873              }
00874                 DrawChip2D();
00875         }
00876  }
00877 /*---------------------------------------------*/
00878 //                     3                        //
00879 //---------------------------------------------//
00880 
00881 bool BeamProfile::FillHitPerChannel(const  MTChannel &channel)
00882 {
00883                 if ( ! this->showHitPerChannelDistribution  || filterOnId(channel ) ||  filterOnCut(channel) ) { return false; }
00884 
00885 
00886                 // Key is Chip string softId
00887                 const MTChipSoftId& csi = channel.GetSoftId();
00888                 string key = csi.toString();
00889 
00890     map<Int_t ,Int_t> *hist =   this->hitPerChannelKeyChipMap[key];
00891 
00892                 // If map for this chip does not exist, create it
00893                 if ( hist == NULL)
00894                 {
00895                         // Create new map only if maxHistogram is not reach
00896           if ( getNbHist() <= maxHistogram)
00897                   {
00898                       // create histogram
00899                             //cout << "Create Histo  for chip[" << channel.GetSoftId().toString() << "]" << endl;
00900                             map<Int_t ,Int_t> *dic = new map<Int_t ,Int_t>();
00901                                         // store new map in hit per channel map which contains one hit per channel map per Chip
00902                       hitPerChannelKeyChipMap[key] = dic;
00903                                                                                                                 cout << "New hitPerChannelKeyChipMap[" << key << "]" << endl;
00904                         }
00905                         else
00906                         {
00907                             cout << "Warning could not create histogram for " <<channel.GetSoftId().toString()  << "because max histogram number is reach ( use -maxHisto to change value." << endl;
00908                             return false;
00909                         }
00910                 }
00911 
00912                 UInt_t channelId = channel.GetHardId();
00913                 // Store min and max deltaT value
00914                 //if ( channelId < minHitPerChannelValue )  { minHitPerChannelValue = channelId; }
00915                 //if ( channelId > maxHitPerChannelValue )  { maxHitPerChannelValue = channelId; }
00916                 if ( detector != NULL)
00917                 {
00918                     const Chamber& chamber      =       detector->getChamberById(channel.GetChamberId());
00919                           //const BoardMap_t  &boards = chamber.getBoardsByDifId(channel.GetDifId());
00920                           const BoardMap_t  &boards = chamber.getBoards();
00921                                 const Board* board = boards.find(channel.GetBoardId())->second;
00922                                 const ChipMap_t &chips = board->getChips();
00923                                 const Chip* chip = chips.find(channel.GetChipId())->second;
00924                                 minHitPerChannelValue = chip->getMinChannelId();
00925                                 maxHitPerChannelValue = chip->getMaxChannelId();
00926                 }
00927                 else
00928                 {
00929                     if ( channelId < minHitPerChannelValue )  { minHitPerChannelValue = channelId; }
00930                     if ( channelId > maxHitPerChannelValue )  { maxHitPerChannelValue = channelId; }
00931                 }
00932 
00933                 // Get Map gor thus chip
00934                 map<Int_t ,Int_t> &tmp =  *hitPerChannelKeyChipMap[key];
00935                 tmp[channelId] = tmp[channelId]+1;
00936   if ( tmp[channelId] > maxHitPerChannel ) { maxHitPerChannel = tmp[channelId];}
00937   if ( tmp[channelId] < minHitPerChannel ) { minHitPerChannel = tmp[channelId];}
00938 
00939         return true;
00940 }
00941 
00942 
00943 /*---------------------------------------------*/
00944 //                                             //
00945 //---------------------------------------------//
00946 void BeamProfile::DrawHitPerChannelDist()
00947 {
00948 // Draw Delta_T distribution
00949         if (  this->showHitPerChannelDistribution )
00950         {
00951             int cur = 0;
00952             for ( map<string,std::map<Int_t ,Int_t>* >::const_iterator iter = hitPerChannelKeyChipMap.begin(); iter != hitPerChannelKeyChipMap.end(); iter++)
00953             {
00954                             cur++;
00955                             if ((*iter).second )
00956                             {
00957                                             //Canvas
00958                                             string c_title("TCancasHitPerChannel");
00959                                             Toolbox::addIntToString(c_title,cur);
00960                                             TCanvas * canvas = new TCanvas(c_title.c_str(),"",10,10,1200,300);
00961 
00962                                             // Histogram configuration
00963                                             string name("HitPerChip_ T_");
00964                                             string title("Hit per channel distribution for Chip  " + (*iter).first);
00965               cout << "Hit per channel distribution for Chip [" << (*iter).first << "]" << endl;
00966                                       Toolbox::addIntToString(name,cur);
00967 
00968                                             // Compute bining
00969                                             UInt_t nbBin =  maxHitPerChannelValue - minHitPerChannelValue;
00970                                             TH1I *newHist = new TH1I(name.c_str(),title.c_str(), nbBin,  minHitPerChannelValue  ,maxHitPerChannelValue + 1);
00971 
00972                                             // Get all DeltaT entry and fill new Histogram with pre conputed weight
00973                                             map<Int_t ,Int_t>   content = *((*iter).second);
00974                                             for ( map<Int_t ,Int_t>::const_iterator iterC = content.begin(); iterC != content.end(); iterC++)
00975                                             {
00976                                                     Int_t val = (*iterC).second;
00977                                                     newHist->Fill((*iterC).first,val);
00978                                             }
00979                                             newHist->Draw();
00980 
00981                             }
00982              }
00983     //          TCanvas * canvas = new TCanvas("Hit per chip","",10,10,1200,300);
00984                                     DrawChannel2D();
00985                                 }
00986 }
00987 /*---------------------------------------------*/
00988 //                     4                        //
00989 // create and configure a delta T distribution histogram per Chip
00990 //---------------------------------------------//
00991 
00992 bool BeamProfile::FillDeltaT(const  MTChannel &channel)
00993 {
00994     if ( ! this->showDeltaDistribution  || filterOnId(channel )) { return false; }
00995    
00996     // Store only DT within user preset limits
00997     long int dt = (channel.GetBcIdDif()-channel.GetBcIdHit());
00998     if ( dt >= timeCutMax ||  dt <= timeCutMin )
00999     {
01000         return false;
01001     }
01002 
01003     // Key is Chip string softId
01004     const MTChipSoftId& csi = channel.GetSoftId();
01005     string key = csi.toString();
01006     map<Int_t ,Int_t> *hist =   this->deltaTKeyChipMap[key];
01007 
01008     // If map for this chip does not exist, create it
01009     if ( hist == NULL)
01010     {
01011         // Create new map only if maxHistogram is not reach
01012         if ( getNbHist() <= maxHistogram)
01013         {
01014             // create histogram
01015             cout << "Create Histo  for chip[" << channel.GetSoftId().toString() << "]" << endl;
01016             map<Int_t ,Int_t> *dic = new map<Int_t ,Int_t>();
01017             // store new map in deltaT map which contains one DeltaT map per Chip
01018             deltaTKeyChipMap[key] = dic;
01019         }
01020         else
01021         {
01022             cout << "Warning could not create histogram for " <<channel.GetSoftId().toString()  << "because max histogram number is reach ( use -maxHisto to change value." << endl;
01023             return false;
01024         }
01025     }
01026 
01027     // Store min and max deltaT value
01028     if ( dt < minDeltaTValue )  { minDeltaTValue = dt; }
01029     if ( dt > maxDeltaTValue )  { maxDeltaTValue = dt; }
01030 
01031     // Get Map gor thus chip
01032     map<Int_t ,Int_t> &tmp =  *deltaTKeyChipMap[key];
01033     tmp[dt] = tmp[dt]+1;
01034 
01035     return true;
01036 }
01037 
01038 
01039 /*---------------------------------------------*/
01040 //                                             //
01041 //---------------------------------------------//
01042 void BeamProfile::DrawDeltaT()
01043 {
01044 // Draw Delta_T distribution
01045         int cur = 0;
01046         for ( map<string,std::map<Int_t ,Int_t>* >::const_iterator iter = deltaTKeyChipMap.begin(); iter != deltaTKeyChipMap.end(); iter++)
01047         {
01048                         cur++;
01049                         if ((*iter).second )
01050                         {
01051                                         //Canvas
01052                                         string c_title("TCancasDeltaT_");
01053                                         Toolbox::addIntToString(c_title,cur);
01054                                         TCanvas * canvas = new TCanvas(c_title.c_str(),"",10,10,1200,300);
01055 
01056                                         // Histogram configuration
01057                                         string name("Delta T_");
01058                                         string title("Delta T ( bcIddif - bcIdhit )  distribution of hits for chip " + (*iter).first);
01059                                         Toolbox::addIntToString(name,cur);
01060 
01061                                         // Compute bining
01062                                         UInt_t nbBin =  maxDeltaTValue - minDeltaTValue;
01063                                         TH1I *newHist = new TH1I(name.c_str(),title.c_str(), nbBin,  minDeltaTValue - 10 ,maxDeltaTValue + 10);
01064 
01065                                         // Get all DeltaT entry and fill new Histogram with pre conputed weight
01066                                         map<Int_t ,Int_t>       content = *((*iter).second);
01067                                         for ( map<Int_t ,Int_t>::const_iterator iterC = content.begin(); iterC != content.end(); iterC++)
01068                                         {
01069                                                 Int_t val = (*iterC).second;
01070                                                 //if  ((*iterC).first <= maxDeltaTValue  && (*iterC).first >= minDeltaTValue  ) newHist->Fill((*iterC).first,val);
01071                                                 newHist->Fill((*iterC).first,val);
01072                                         }
01073                                         newHist->Draw();
01074                         }
01075          }
01076 }
01077 /*---------------------------------------------*/
01078 //                                             //
01079 //---------------------------------------------//
01080 
01081 bool BeamProfile::FillHotChamber(const MTEvent& evt)
01082 {
01083     if ( showHotChamber)
01084     {
01085         unsigned int hot  = GetHotChamber(evt);
01086         chamberHotHist->Fill(hot);
01087         if (hot>=1)
01088         {
01089             unsigned int nchannel = evt.GetNchannel();
01090             for (int j=0;j<nchannel;j++)
01091             {
01092                 MTChannel* channel = (MTChannel*)evt.GetChannels()->UncheckedAt(j);
01093                 //this->showXYDistribution=true;
01094                 FillXyDist(*channel);
01095             }
01096         }
01097     }
01098 return true;
01099 }
01100 /*---------------------------------------------*/
01101 //                                             //
01102 //---------------------------------------------//
01103 
01104 unsigned int BeamProfile::GetHotChamber(const MTEvent& evt)
01105 {
01106     // Fill chamber  if hit number (with ADC uuper to adcVal)  > hitNum
01107 
01108     int adcVal = adc;
01109     int hitNum = nbhit;
01110 
01111 
01112     //if ( ! this->showDeltaDistribution  || filterOnId(channel )) { return false; }
01113 
01114     // Store only DT within user preset limits
01115     //timestampHist->Fill(channel.GetTimestamp());
01116 
01117     map<ui16,int> nbValidHit ;
01118 
01119 
01120     for(int i=0;i<evt.GetNchannel() ;i++)
01121     {
01122         MTChannel *channel = (MTChannel*)evt.GetChannels()->At(i);
01123 
01124 
01125         if ( channel->GetAnalogValue() >= adcVal )
01126         {
01127             if ( nbValidHit.find(channel->GetChamberId()) == nbValidHit.end() )
01128             {
01129                 nbValidHit[channel->GetChamberId()] = 0;
01130             }
01131             ui32 validHit = nbValidHit.find(channel->GetChamberId())->second  + 1;
01132             nbValidHit[channel->GetChamberId()] = validHit;
01133         }
01134     } // end event loop
01135 
01136     ui16 nbChamberHot = 0;
01137     for ( map<ui16 ,int>::const_iterator iterC = nbValidHit.begin(); iterC != nbValidHit.end(); iterC++)
01138     {
01139         int val = (*iterC).second;
01140         ui16 chamberId =(*iterC).first;
01141         if ( val <= hitNum)
01142         {
01143             nbChamberHot++;
01144         }
01145     }
01146 
01147     return nbChamberHot ;
01148 }
01149 /*---------------------------------------------*/
01150 //                                             //
01151 //---------------------------------------------//
01152 void BeamProfile::DrawHotChamber()
01153 
01154 {
01155     if ( showHotChamber)
01156     {
01157                                 TCanvas * canvas = new TCanvas("HotChamber","",10,10,1200,300);
01158         chamberHotHist->Draw();
01159         //DrawXyDist();
01160     }
01161 
01162 }
01163 
01164 
01165 /*---------------------------------------------*/
01166 //                                             //
01167 //---------------------------------------------//
01168 
01169 void BeamProfile::DrawChannel2D()
01170 {  //un-named script to be run in ROOT framework
01171 
01172                 ui32 chamberId, difId, chipId;
01173 
01174                   chipId =    this->getChipId()  ;
01175     chamberId = this->getChamberId();
01176     difId =     this->getDifId()  ;
01177 
01178 
01179 
01180     if ( detector == NULL)
01181     {
01182     cout << endl << endl << " WARNING: XML file mandatory to draw colored channel hits. Please use -xml option." << endl;
01183     return;
01184     }
01185     string txt = "";
01186 
01187     int xLength, yLength = 0;
01188 
01189 
01190 
01191 
01192     try
01193                 {
01194       const Chip& chip =         detector->getDifById(difId).getChipById(chipId);
01195                     Float_t xLength = chip.getXLength() ;
01196                     Float_t yLength = chip.getYLength() ;
01197 
01198 
01199         int hMax = 200;
01200         int vMax = 200;
01201         int hCanvas,vCanvas;
01202 
01203         if ( yLength > xLength)
01204         {
01205             vCanvas = vMax;
01206             float coef = (float) yLength / (float)xLength;
01207             cout << "--yLength["<< yLength << "]" << endl;
01208             cout << "--xLength["<< xLength << "]" << endl;
01209             cout << "--coef["<< coef << "]" << endl;
01210             hCanvas = int(hMax / coef);
01211         }
01212         else
01213         {
01214             hCanvas = hMax;
01215             float coef = (float)xLength / (float)yLength;
01216             cout << "--yLength["<< yLength << "]" << endl;
01217             cout << "--xLength["<< xLength << "]" << endl;
01218             cout << "--coef["<< coef << "]" << endl;
01219             vCanvas = int(vMax / coef);
01220         }
01221 
01222         TCanvas *c1 = new TCanvas("c1","Analyze.mac",vCanvas,hCanvas);
01223 
01224 
01225         c1->Range(0,0,yLength,xLength);// (xmin,ymin,xmax,ymax
01226         int nbChannel = 0;
01227         int color = 0;
01228 
01229 
01230         const ChannelMap_t &channels = chip.getChannels();
01231         for (ChannelMap_t::const_iterator channelIt = channels.begin(); channelIt != channels.end(); ++channelIt)
01232         {
01233             Channel& channel = *(channelIt->second);
01234 
01235             float x=channel.getX() -  chip.getX();// - chip.getBoard().getX() -  chamber.getX();
01236             float y=channel.getY() -  chip.getY();// - chip.getBoard().getY() - chamber.getY();
01237 
01238             float z=channel.getZ() ;
01239 
01240             cout << "channel X()[" << channel.getX() << "] Y[" << channel.getY() << "]" <<  endl;
01241 
01242             stringstream currentpad;
01243             currentpad<<channel.getHardId();
01244 
01245             float x2 = x+.9;
01246             float y2 = y+.9;
01247 
01248 
01249 
01250             TPaveLabel *pl1= new TPaveLabel(y,  x,y2,   x2,currentpad.str().c_str()); // x1 x2 y1 y2
01251 
01252 
01253 
01254                         const ChipSoftId& csi = (ChipSoftId)channel.getSoftId();
01255                         string key = csi.toString();
01256                 int value = 2;
01257                 try
01258                 {
01259                     if (hitPerChannelKeyChipMap[key] != NULL )
01260                     {
01261                         map<Int_t ,Int_t> &tmp =  *hitPerChannelKeyChipMap[key];
01262                         ui32 width = maxHitPerChannel - minHitPerChannel;
01263                        // cout << "maxHitPerChannel[" << maxHitPerChannel << "]" << endl;
01264                        // cout << "minHitPerChannel[" << minHitPerChannel << "]" << endl;
01265                        // cout << "width[" << width << "]" << endl;
01266 
01267                         value = tmp[channel.getHardId()] ;
01268 
01269                                                                                                                                                                                                 float s1 = float (width / 6) ;
01270                                                                                                                                                                                                 float s2 = float (2 * width / 6) ;
01271                                                                                                                                                                                                 float s3 = float (3 * width / 6) ;
01272                                                                                                                                                                                                 float s4 = float (4 * width / 6) ;
01273                                                                                                                                                                                                 float s5 = float (5 * width / 6) ;
01274 
01275                         if ( value > s5)         { value = kRed; }
01276                                                                                                                                                                                                 else if ( value > s4)    { value = kOrange; }
01277                                                                                 else if ( value > s3)    { value = kYellow; }
01278                                                                                                                                                                                                 else if ( value > s2)    { value = kGreen ; }
01279                         else if ( value > s1 )   { value = kCyan; }
01280                                                                                                                                                                                                 else                     { value = kBlue  ; }
01281                     }
01282                 }
01283                 catch (MicroException e)
01284                 {
01285                 //                      cout << "no map for key[" << key << "]" << endl;
01286                 }
01287 
01288 
01289             pl1->SetFillColor(value);
01290             pl1->Draw();
01291         }
01292 
01293 
01294         cout << "Vue des PADs en direct     " << endl;
01295         cout << "                                             X " << endl;
01296         cout << "                                               " << endl;
01297         cout << "                                             ^ " << endl;
01298         cout << "                                             | " << endl;
01299         cout << "                                             | " << endl;
01300         cout << "                                             | " << endl;
01301         cout << "                                             | " << endl;
01302         cout << "                                             | " << endl;
01303         cout << "                                             | " << endl;
01304         cout << "                                             X----->Y " << endl;
01305         cout << "SYSTEM de COORDONNEES: (0,0) en bas a gauche 0,0     " << endl;
01306         cout << "  Z sortant." << endl;
01307         cout << "La DIF se trouve a gauche de l'ecran)  " << endl;
01308 
01309     } //end try
01310     catch ( MicroException e )
01311     {
01312         cout << e.getMessage() << endl;
01313     }
01314 
01315 }
01316 
01317 
01318 /*---------------------------------------------*/
01319 //                                             //
01320 //---------------------------------------------//
01321 
01322 void BeamProfile::DrawChip2D()
01323 {  //un-named script to be run in ROOT framework
01324 
01325                 ui32 chamberId, difId, chipId;
01326 
01327     chamberId = this->getChamberId();
01328     difId =     this->getDifId()  ;
01329 
01330 
01331 
01332     if ( detector == NULL)
01333     {
01334     cout << endl << endl << " WARNING: XML file mandatory to draw colored channel hits. Please use -xml option." << endl;
01335     return;
01336     }
01337     string txt = "";
01338 
01339     int xLength, yLength = 0;
01340 
01341 
01342 
01343 
01344     try
01345                 {
01346       const Dif& dif =   detector->getChamberById(chamberId).getDifById(difId);
01347                                                 const Board& board = dif.getBoardById(boardId);
01348                     Float_t xLength = board.getXLength() ;
01349                     Float_t yLength = board.getYLength() ;
01350 
01351 
01352         int hMax = 200;
01353         int vMax = 200;
01354         int hCanvas,vCanvas;
01355 
01356         if ( yLength > xLength)
01357         {
01358             vCanvas = vMax;
01359             float coef = (float) yLength / (float)xLength;
01360             cout << "--yLength["<< yLength << "]" << endl;
01361             cout << "--xLength["<< xLength << "]" << endl;
01362             cout << "--coef["<< coef << "]" << endl;
01363             hCanvas = int(hMax / coef);
01364         }
01365         else
01366         {
01367             hCanvas = hMax;
01368             float coef = (float)xLength / (float)yLength;
01369             cout << "--yLength["<< yLength << "]" << endl;
01370             cout << "--xLength["<< xLength << "]" << endl;
01371             cout << "--coef["<< coef << "]" << endl;
01372             vCanvas = int(vMax / coef);
01373         }
01374 
01375         TCanvas *c1 = new TCanvas("c1","Analyze.mac",vCanvas,hCanvas);
01376 
01377 
01378         c1->Range(0,0,yLength,xLength);// (xmin,ymin,xmax,ymax
01379         int color = 0;
01380 
01381 
01382         const ChipMap_t &chips = board.getChips();
01383         for (ChipMap_t::const_iterator chipIt = chips.begin(); chipIt != chips.end(); ++chipIt)
01384         {
01385             Chip& chip = *(chipIt->second);
01386 
01387             float x=chip.getX() -  board.getX();// - chip.getBoard().getX() -  chamber.getX();
01388             float y=chip.getY() -  board.getY();// - chip.getBoard().getY() - chamber.getY();
01389 
01390 
01391             stringstream currentpad;
01392             currentpad<<chip.getId();
01393 
01394             float x2 = x+chip.getXLength();
01395             float y2 = y+chip.getYLength();
01396 
01397 
01398 
01399             TPaveLabel *pl1= new TPaveLabel(y,  x,y2,   x2,currentpad.str().c_str()); // x1 x2 y1 y2
01400 
01401 
01402 
01403                         const DifSoftId& csi = (DifSoftId)chip.getChipSoftId();
01404                         string key = csi.toString();
01405                 int value = 2;
01406                 try
01407                 {
01408                                                                                                                                 cout << "key[" << key << "]" << endl;
01409 
01410                     if (hitPerChipKeyChamberDifMap[key] != NULL )
01411 
01412                     {
01413                         map<Int_t ,Int_t> &tmp =  *hitPerChipKeyChamberDifMap[key];
01414                         ui32 width = maxHitPerChip - minHitPerChip;
01415                                                                                                                                                                                                 cout << endl << endl << "---------- width[" << width << "]" << endl;
01416                                                                                                                                                                                                 cout << "value[" << value << "]" << endl;
01417 
01418                         value = tmp[chip.getId()] ;
01419 
01420                                                                                                                                                                                                 float s1 = float (width / 6) ;
01421                                                                                                                                                                                                 float s2 = float (2 * width / 6) ;
01422                                                                                                                                                                                                 float s3 = float (3 * width / 6) ;
01423                                                                                                                                                                                                 float s4 = float (4 * width / 6) ;
01424                                                                                                                                                                                                 float s5 = float (5 * width / 6) ;
01425 
01426 cout << "s1[" << s1 << "]" << endl;
01427 cout << "s2[" << s2 << "]" << endl;
01428 cout << "s3[" << s3 << "]" << endl;
01429 cout << "s4[" << s4 << "]" << endl;
01430 cout << "s5[" << s5 << "]" << endl;
01431                         if ( value > s5)         { value = kRed; }
01432                                                                                                                                                                                                 else if ( value > s4)    { value = kOrange; }
01433                                                                                 else if ( value > s3)    { value = kYellow; }
01434                                                                                                                                                                                                 else if ( value > s2)    { value = kGreen ; }
01435                         else if ( value > s1 )   { value = kCyan; }
01436                                                                                                                                                                                                 else                     { value = kBlue  ; }
01437                                                                                                                                                                                                 cout << "value[" << value << "]" << endl << endl;
01438                     }
01439                 }
01440                 catch (MicroException e)
01441                 {
01442                 //                      cout << "no map for key[" << key << "]" << endl;
01443                 }
01444 
01445 
01446             pl1->SetFillColor(value);
01447             pl1->Draw();
01448         }
01449 
01450 
01451         cout << "Vue des PADs en direct     " << endl;
01452         cout << "                                             X " << endl;
01453         cout << "                                               " << endl;
01454         cout << "                                             ^ " << endl;
01455         cout << "                                             | " << endl;
01456         cout << "                                             | " << endl;
01457         cout << "                                             | " << endl;
01458         cout << "                                             | " << endl;
01459         cout << "                                             | " << endl;
01460         cout << "                                             | " << endl;
01461         cout << "                                             X----->Y " << endl;
01462         cout << "SYSTEM de COORDONNEES: (0,0) en bas a gauche 0,0     " << endl;
01463         cout << "  Z sortant." << endl;
01464         cout << "La DIF se trouve a gauche de l'ecran)  " << endl;
01465 
01466     } //end try
01467     catch ( MicroException e )
01468     {
01469         cout << e.getMessage() << endl;
01470     }
01471 
01472 }
01473 

Generated on Mon Jan 7 13:15:22 2013 for MicromegasFramework by  doxygen 1.4.7