00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014 #include "MessageService/MsgService.h"
00015
00016 #include "LISummary/LIPmt.h"
00017
00018 #include <cmath>
00019
00020 ClassImp(LIPmt)
00021
00022 CVSID("$Id: LIPmt.cxx,v 1.7 2007/01/15 20:12:15 rhatcher Exp $");
00023
00024
00025
00026 LIPmt::LIPmt()
00027 {
00028 MSG("LIPmt", Msg::kDebug)
00029 <<"Running LIPmt default constructor..."<<endl;
00030
00031 fInitialised=false;
00032
00033 MSG("LIPmt", Msg::kDebug)
00034 <<"Finished LIPmt default constructor"<<endl;
00035 }
00036
00037
00038
00039 LIPmt::LIPmt(Int_t numPixels,Int_t numPixelSpots)
00040 {
00041 MSG("LIPmt", Msg::kDebug)
00042 <<"Running LIPmt constructor..."<<endl;
00043
00044 this->InitialiseVariables(numPixels,numPixelSpots);
00045 fInitialised=true;
00046
00047 MSG("LIPmt", Msg::kDebug)
00048 <<"Finished LIPmt constructor"<<endl;
00049 }
00050
00051
00052
00053 LIPmt::~LIPmt()
00054 {
00055 MSG("LIPmt", Msg::kDebug)
00056 <<"Running LIPmt destructor..."<<endl;
00057
00058
00059 MSG("LIPmt", Msg::kDebug)
00060 <<"Finished LIPmt destructor"<<endl;
00061 }
00062
00063
00064
00065 bool operator==(LIPmt a, LIPmt b)
00066 {
00067 return a.GetGains()==b.GetGains();
00068 }
00069
00070
00071
00072 bool operator<(LIPmt a, LIPmt b)
00073 {
00074 return a.GetGains().size()<b.GetGains().size();
00075 }
00076
00077
00078
00079 void LIPmt::Initialise(Int_t numPixels,Int_t numPixelSpots)
00080 {
00081 MSG("LIPmt",Msg::kVerbose)
00082 <<"Running Initialise method..."<<endl;
00083
00084 if (!fInitialised){
00085 this->InitialiseVariables(numPixels,numPixelSpots);
00086 fInitialised=true;
00087 }
00088
00089 MSG("LIPmt",Msg::kVerbose)
00090 <<"Initialise method finished"<<endl;
00091 }
00092
00093
00094
00095 void LIPmt::InitialiseVariables(Int_t numPixels,Int_t numPixelSpots)
00096 {
00097 MSG("LIPmt",Msg::kVerbose)
00098 <<"Running InitialiseVariables method..."<<endl;
00099
00100 MSG("LIPmt",Msg::kDebug)
00101 <<"Initialised variables, fInitialised="<<fInitialised
00102 <<", numPixels="<<numPixels<<", numPixelSpots="<<numPixelSpots
00103 <<endl;
00104
00105 fNumPixels=numPixels;
00106 fNumPixelSpots=numPixelSpots;
00107 fGainsSum=0;
00108 fGainsNum=0;
00109 fS="";
00110
00111
00112 for (Int_t spot=0;spot<fNumPixels*fNumPixelSpots;spot++){
00113 fGains.push_back(0);
00114 fCounter.push_back(0);
00115 }
00116
00117 if (numPixelSpots>1){
00118
00119 for (Int_t pix=0;pix<fNumPixels;pix++){
00120 fPixelGainsSum.push_back(0);
00121 fPixelGainsNum.push_back(0);
00122 }
00123 }
00124
00125 MSG("LIPmt",Msg::kVerbose)
00126 <<"InitialiseVariables method finished"<<endl;
00127 }
00128
00129
00130
00131 Bool_t LIPmt::IsEmpty() const
00132 {
00133 if (fGainsNum>0) return false;
00134 else return true;
00135 }
00136
00137
00138
00139 void LIPmt::Print(Option_t* ) const
00140 {
00141 if (!fInitialised) return;
00142
00143
00144 if (fNumPixels<=0){
00145 MSG("LIPmt",Msg::kWarning)
00146 <<"Num of pixels <=0, fNumPixels="<<fNumPixels
00147 <<", fNumPixelSpots="<<fNumPixelSpots<<endl
00148 <<"The object must be initialised"<<endl;
00149 return;
00150 }
00151
00152 Int_t pmtWidth=static_cast<Int_t>
00153 (sqrt(static_cast<Float_t>(fNumPixels)));
00154
00155 for(int row=0;row<pmtWidth;row++){
00156 for(int p=0;p<pmtWidth;p++){
00157
00158 MSG("LIPmt",Msg::kInfo)
00159 <<static_cast<Int_t>(this->GetPixelGain(row*pmtWidth+p))<<" ";
00160 }
00161
00162 MSG("LIPmt",Msg::kInfo)<<endl;
00163 }
00164 }
00165
00166
00167
00168 TH2F* LIPmt::GetPmtFaceMap(string sTitle) const
00169 {
00170 if (!fInitialised) return 0;
00171
00172
00173 if (fNumPixels<=0){
00174 MSG("LIPmt",Msg::kWarning)
00175 <<"Num of pixels <=0, fNumPixels="<<fNumPixels
00176 <<", fNumPixelSpots="<<fNumPixelSpots<<endl
00177 <<"The object must be initialised"<<endl;
00178 return 0;
00179 }
00180
00181 Int_t pmtWidth=static_cast<Int_t>
00182 (sqrt(static_cast<Float_t>(fNumPixels)));
00183
00184 TH2F* hPmtFace=new TH2F(sTitle.c_str(),sTitle.c_str(),
00185 pmtWidth+2,-1,pmtWidth+1,
00186 pmtWidth+2,-1,pmtWidth+1);
00187 hPmtFace->SetTitle(sTitle.c_str());
00188 hPmtFace->SetFillColor(2);
00189
00190
00191 for(int row=0;row<pmtWidth;row++){
00192 for(int p=0;p<pmtWidth;p++){
00193
00194 hPmtFace->Fill(p,row,this->GetPixelGain(row*pmtWidth+p));
00195
00196 }
00197 }
00198
00199 return hPmtFace;
00200 }
00201
00202
00203
00204 void LIPmt::SetPoint(Int_t pixel,Int_t pixelSpot,Double_t gain)
00205 {
00206 MSG("LIPmt",Msg::kVerbose)<<"Running SetPoint method..."<<endl;
00207
00208
00209 pixelSpot--;
00210
00211 MSG("LIPmt",Msg::kDebug)
00212 <<"("<<pixel<<","<<pixelSpot<<")"
00213 <<" Setting point: gain="<<gain<<endl;
00214
00215 if (pixel>=0 && pixel<fNumPixels){
00216 if (pixelSpot>=0 && pixelSpot<fNumPixelSpots){
00217
00218 Int_t spotIndex=pixel*fNumPixelSpots+pixelSpot;
00219
00220
00221 fGainsSum+=gain;
00222 fGainsNum++;
00223
00224
00225 fGains[spotIndex]=gain;
00226
00227
00228 if (fCounter[spotIndex]!=0){
00229 MSG("LIPmt",Msg::kWarning)
00230 <<"This pixel and pixelSpot have already been set!"<<endl
00231 <<"Pixel="<<pixel<<", pixelSpot="<<pixelSpot
00232 <<", counter="<<fCounter[spotIndex]<<endl;
00233 }
00234 fCounter[spotIndex]++;
00235
00236
00237 if (fNumPixelSpots>1){
00238 fPixelGainsSum[pixel]+=gain;
00239 fPixelGainsNum[pixel]++;
00240 }
00241
00242 }
00243 else{
00244 MSG("LIPmt",Msg::kWarning)
00245 <<"Pixel Spot is wrong, pixel="<<pixel
00246 <<", pixelSpot="<<pixelSpot<<", gain="<<gain<<endl;
00247 }
00248 }
00249 else{
00250 MSG("LIPmt",Msg::kWarning)
00251 <<"Pixel is wrong, pixel="<<pixel
00252 <<", pixelSpot="<<pixelSpot<<", gain="<<gain<<endl;
00253 }
00254
00255 MSG("LIPmt",Msg::kVerbose)<<"SetPoint method finished"<<endl;
00256 }
00257
00258
00259
00260 void LIPmt::AddMultiPoint(Int_t pixel,Int_t pixelSpot,Double_t gain)
00261 {
00265
00266 MSG("LIPmt",Msg::kVerbose)<<"Running AddMultiPoint method..."<<endl;
00267
00268
00269 pixelSpot--;
00270
00271 MSG("LIPmt",Msg::kDebug)
00272 <<"("<<pixel<<","<<pixelSpot<<")"
00273 <<" Adding new point: gain="<<gain<<endl;
00274
00275 if (pixel>=0 && pixel<fNumPixels){
00276 if (pixelSpot>=0 && pixelSpot<fNumPixelSpots){
00277
00278 Int_t spotIndex=pixel*fNumPixelSpots+pixelSpot;
00279
00280
00281 fGainsSum+=gain;
00282 fGainsNum++;
00283
00284
00285 fGains[spotIndex]+=gain;
00286 fCounter[spotIndex]++;
00287
00288
00289 if (fNumPixelSpots>1){
00290 fPixelGainsSum[pixel]+=gain;
00291 fPixelGainsNum[pixel]++;
00292 }
00293
00294 }
00295 else{
00296 MSG("LIPmt",Msg::kWarning)
00297 <<"Pixel Spot is wrong, pixel="<<pixel
00298 <<", pixelSpot="<<pixelSpot<<", gain="<<gain<<endl;
00299 }
00300 }
00301 else{
00302 MSG("LIPmt",Msg::kWarning)
00303 <<"Pixel is wrong, pixel="<<pixel
00304 <<", pixelSpot="<<pixelSpot<<", gain="<<gain<<endl;
00305 }
00306
00307 MSG("LIPmt",Msg::kVerbose)<<"AddMultiPoint method finished"<<endl;
00308 }
00309
00310
00311
00312 Double_t LIPmt::GetGain(Int_t pixel,Int_t pixelSpot) const
00313 {
00314
00315 pixelSpot--;
00316
00317 if (pixel>=0 && pixel<fNumPixels){
00318 if (pixelSpot>=0 && pixelSpot<fNumPixelSpots){
00319 Int_t spotIndex=pixel*fNumPixelSpots+pixelSpot;
00320
00321
00322 if (fCounter[spotIndex]>0){
00323 return fGains[spotIndex]/fCounter[spotIndex];
00324 }
00325 }
00326 }
00327 return -1;
00328 }
00329
00330
00331
00332 const vector<Double_t>& LIPmt::GetGains() const
00333 {
00334 MSG("LIPmt",Msg::kVerbose)
00335 <<"Running GetGain method..."<<endl;
00336
00337 MSG("LIPmt",Msg::kVerbose)
00338 <<"GetGain method finished"<<endl;
00339 return fGains;
00340 }
00341
00342
00343
00344 Double_t LIPmt::GetAvPmtGain() const
00345 {
00346 MSG("LIPmt",Msg::kVerbose)
00347 <<"Running GetAvPmtGain method..."<<endl;
00348
00349 Double_t avGain=-1;
00350 if (fGainsNum>0) avGain=fGainsSum/fGainsNum;
00351
00352 MSG("LIPmt",Msg::kVerbose)
00353 <<"GetAvPmtGain method finished"<<endl;
00354 return avGain;
00355 }
00356
00357
00358
00359 Double_t LIPmt::GetPixelGain(Int_t pixel) const
00360 {
00361 MSG("LIPmt",Msg::kVerbose)
00362 <<"Running GetPixelGain method..."<<endl;
00363
00364 Double_t pixelGain=-1;
00365
00366 if (pixel>=0 && pixel<fNumPixels){
00367
00368
00369 if (fNumPixelSpots>1){
00370
00371 if (fPixelGainsNum[pixel]>0){
00372 pixelGain=fPixelGainsSum[pixel]/fPixelGainsNum[pixel];
00373 }
00374 }
00375 else {
00376
00377 if (fCounter[pixel]>0) pixelGain=fGains[pixel]/fCounter[pixel];
00378 }
00379 }
00380 else {
00381 MSG("LIPmt",Msg::kWarning)<<"Pixel is wrong, pixel="<<pixel<<endl;
00382 }
00383
00384 MSG("LIPmt",Msg::kVerbose)
00385 <<"GetPixelGain method finished"<<endl;
00386 return pixelGain;
00387 }
00388
00389
00390
00391 Int_t LIPmt::GetPixelNum(Int_t pixel) const
00392 {
00393 MSG("LIPmt",Msg::kVerbose)
00394 <<"Running GetPixelNum method..."<<endl;
00395
00396 Int_t pixelNum=0;
00397
00398 if (pixel>=0 && pixel<fNumPixels){
00399
00400
00401 if (fNumPixelSpots>1){
00402 pixelNum=fPixelGainsNum[pixel];
00403 }
00404 else {
00405
00406 pixelNum=fCounter[pixel];
00407 }
00408 }
00409 else {
00410 MSG("LIPmt",Msg::kWarning)<<"Pixel is wrong, pixel="<<pixel<<endl;
00411 }
00412
00413 MSG("LIPmt",Msg::kVerbose)
00414 <<"GetPixelNum method finished"<<endl;
00415 return pixelNum;
00416 }
00417
00418
00419
00420 vector<Int_t> LIPmt::GetNearestNeighbours(Int_t pixel) const
00421 {
00422 MSG("LIPmt",Msg::kVerbose)
00423 <<"Running GetNearestNeighbours method..."<<endl;
00424
00425 vector<Int_t> nearestNeighbours;
00426
00427
00428 if (fNumPixels<=0){
00429 MSG("LIPmt",Msg::kWarning)
00430 <<"Num of pixels <=0, fNumPixels="<<fNumPixels
00431 <<", fNumPixelSpots="<<fNumPixelSpots<<endl
00432 <<"The object must be initialised, returning empty vector"<<endl;
00433 return nearestNeighbours;
00434 }
00435
00436 if (pixel>=0 && pixel<fNumPixels){
00437
00438 Int_t pmtWidth=static_cast
00439 <Int_t>(sqrt(static_cast<Float_t>(fNumPixels)));
00440
00441
00442 if (pixel==0 || pixel==pmtWidth-1 ||
00443 pixel==fNumPixels-pmtWidth || pixel==fNumPixels-1){
00444
00445 if (pixel==0){
00446 nearestNeighbours.push_back(pixel+1);
00447 nearestNeighbours.push_back(pixel+pmtWidth);
00448 }
00449 else if (pixel==pmtWidth-1){
00450 nearestNeighbours.push_back(pixel-1);
00451 nearestNeighbours.push_back(pixel+pmtWidth);
00452 }
00453 else if (pixel==fNumPixels-pmtWidth){
00454 nearestNeighbours.push_back(pixel-pmtWidth);
00455 nearestNeighbours.push_back(pixel+1);
00456 }
00457 else if (pixel==fNumPixels-1){
00458 nearestNeighbours.push_back(pixel-pmtWidth);
00459 nearestNeighbours.push_back(pixel-1);
00460 }
00461 }
00462
00463 else if (pixel<pmtWidth || pixel>=fNumPixels-pmtWidth ||
00464 pixel%pmtWidth==0 || pixel%pmtWidth==pmtWidth-1){
00465
00466 if (pixel<pmtWidth){
00467 nearestNeighbours.push_back(pixel-1);
00468 nearestNeighbours.push_back(pixel+1);
00469 nearestNeighbours.push_back(pixel+pmtWidth);
00470 }
00471
00472 else if (pixel%pmtWidth==0){
00473 nearestNeighbours.push_back(pixel-pmtWidth);
00474 nearestNeighbours.push_back(pixel+1);
00475 nearestNeighbours.push_back(pixel+pmtWidth);
00476 }
00477 else if (pixel%pmtWidth==pmtWidth-1){
00478 nearestNeighbours.push_back(pixel-pmtWidth);
00479 nearestNeighbours.push_back(pixel-1);
00480 nearestNeighbours.push_back(pixel+pmtWidth);
00481 }
00482 else if (pixel>=fNumPixels-pmtWidth){
00483 nearestNeighbours.push_back(pixel-pmtWidth);
00484 nearestNeighbours.push_back(pixel-1);
00485 nearestNeighbours.push_back(pixel+1);
00486 }
00487 }
00488
00489 else {
00490 nearestNeighbours.push_back(pixel-pmtWidth);
00491 nearestNeighbours.push_back(pixel-1);
00492 nearestNeighbours.push_back(pixel+1);
00493 nearestNeighbours.push_back(pixel+pmtWidth);
00494 }
00495 }
00496 else {
00497 MSG("LIPmt",Msg::kWarning)<<"Pixel is wrong, pixel="<<pixel<<endl;
00498 }
00499
00500 MSG("LIPmt",Msg::kVerbose)
00501 <<"Finished GetNearestNeighbours method"<<endl;
00502 return nearestNeighbours;
00503 }
00504
00505
00506
00507 Double_t LIPmt::GetNearestNeighboursAvGain(Int_t pixel) const
00508 {
00509 MSG("LIPmt",Msg::kVerbose)
00510 <<"Running GetNearestNeighboursAvGain method..."<<endl;
00511
00512 Double_t pixelGain=0;
00513 Int_t counter=0;
00514
00515 if (pixel>=0 && pixel<fNumPixels){
00516
00517 vector<Int_t> nearestNeighbours=this->GetNearestNeighbours(pixel);
00518 vector<Int_t>::iterator nnPixel=nearestNeighbours.begin();
00519
00520
00521 while (nnPixel!=nearestNeighbours.end()){
00522
00523
00524 if (fNumPixelSpots>1){
00525
00526 if (fPixelGainsNum[*nnPixel]>0){
00527 pixelGain+=fPixelGainsSum[*nnPixel]/fPixelGainsNum[*nnPixel];
00528 counter++;
00529 }
00530 }
00531
00532 else {
00533
00534 if (fCounter[*nnPixel]>0){
00535 pixelGain+=fGains[*nnPixel]/fCounter[*nnPixel];
00536 counter++;
00537 }
00538 }
00539 nnPixel++;
00540 }
00541
00542
00543 if (counter>0) pixelGain/=counter;
00544 else pixelGain=-1;
00545 }
00546 else {
00547 pixelGain=-1;
00548 MSG("LIPmt",Msg::kWarning)<<"Pixel is wrong, pixel="<<pixel<<endl;
00549 }
00550
00551 MSG("LIPmt",Msg::kVerbose)
00552 <<"Finished GetNearestNeighboursAvGain method"<<endl;
00553 return pixelGain;
00554 }
00555
00556
00557
00558 Int_t LIPmt::GetNearestNeighboursNum(Int_t pixel) const
00559 {
00560 MSG("LIPmt",Msg::kVerbose)
00561 <<"Running GetNearestNeighboursNum method..."<<endl;
00562
00563 Int_t totalNum=0;
00564 Int_t counter=0;
00565
00566 if (pixel>=0 && pixel<fNumPixels){
00567
00568 vector<Int_t> nearestNeighbours=this->GetNearestNeighbours(pixel);
00569 vector<Int_t>::iterator nnPixel=nearestNeighbours.begin();
00570
00571
00572 while (nnPixel!=nearestNeighbours.end()){
00573
00574
00575 if (fNumPixelSpots>1){
00576
00577 if (fPixelGainsNum[*nnPixel]>0){
00578 totalNum+=fPixelGainsNum[*nnPixel];
00579 counter++;
00580 }
00581 }
00582
00583 else {
00584
00585 if (fCounter[*nnPixel]>0){
00586 totalNum+=fCounter[*nnPixel];
00587 counter++;
00588 }
00589 }
00590 nnPixel++;
00591 }
00592
00593
00594 if (counter<=0) totalNum=-1;
00595 }
00596 else {
00597 totalNum=-1;
00598 MSG("LIPmt",Msg::kWarning)<<"Pixel is wrong, pixel="<<pixel<<endl;
00599 }
00600
00601 MSG("LIPmt",Msg::kVerbose)
00602 <<"Finished GetNearestNeighboursNum method"<<endl;
00603 return totalNum;
00604 }
00605
00606
00607
00608 void LIPmt::PrintNearestNeighbours() const
00609 {
00610 MSG("LIPmt",Msg::kInfo)
00611 <<"Running PrintNearestNeighbours method..."<<endl;
00612
00613
00614 if (fNumPixels<=0){
00615 MSG("LIPmt",Msg::kWarning)
00616 <<"Num of pixels <=0, fNumPixels="<<fNumPixels
00617 <<", fNumPixelSpots="<<fNumPixelSpots<<endl
00618 <<"The object must be initialised"<<endl;
00619 }
00620
00621 for (Int_t i=0;i<fNumPixels;i++){
00622 vector<Int_t> nearestNeighbours=this->GetNearestNeighbours(i);
00623
00624 string sNn=lookup.GetVectorAsString(nearestNeighbours);
00625
00626 MSG("LIPmt",Msg::kInfo)
00627 <<"Pixel="<<i<<" has nearest neighbours: "<<sNn;
00628 }
00629
00630 MSG("LIPmt",Msg::kInfo)
00631 <<"Finished PrintNearestNeighbours method"<<endl;
00632 }
00633
00634
00635
00636 void LIPmt::FillGainsHisto(TH1F* hGainAvDet) const
00637 {
00638 MSG("LIPmt",Msg::kDebug)<<"Running FillHisto method..."<<endl;
00639
00640
00641 if (hGainAvDet && fGains.size()>0){
00642
00643 vector<Double_t>::const_iterator gain=fGains.begin();
00644 vector<Int_t>::const_iterator counter=fCounter.begin();
00645
00646 while(gain!=fGains.end()){
00647
00648 if (*counter>0){
00649
00650 hGainAvDet->Fill(*gain/(*counter));
00651 }
00652 gain++;
00653 counter++;
00654 }
00655 }
00656
00657 MSG("LIPmt",Msg::kDebug)<<"Finished FillHisto method"<<endl;
00658 }
00659
00660
00661