00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00015 #include <iostream>
00016 #include <vector>
00017 #include <fstream>
00018 #include <cmath>
00019 #include <stdexcept>
00020
00021 #include "TCanvas.h"
00022 #include "TDatime.h"
00023 #include "TError.h"
00024 #include "TF1.h"
00025 #include "TH2.h"
00026 #include "TObject.h"
00027 #include "TPad.h"
00028 #include "TPaveText.h"
00029 #include "TProfile2D.h"
00030 #include "TStyle.h"
00031 #include "TText.h"
00032 #include "TRandom.h"
00033 #include "TStopwatch.h"
00034
00035
00036 #include "Calibrator/CalADCtoPE.h"
00037 #include "Calibrator/CalADCtoPEs.h"
00038 #include "Calibrator/CalMIPCalibration.h"
00039 #include "Calibrator/CalStripToStrip.h"
00040 #include "Calibrator/CalStripAtten.h"
00041 #include "Conventions/Detector.h"
00042 #include "Conventions/StripEnd.h"
00043 #include "DatabaseInterface/DbiResultPtr.h"
00044 #include "DatabaseInterface/DbiValidityRec.h"
00045 #include "DatabaseInterface/DbiWriter.h"
00046 #include "MessageService/MsgService.h"
00047 #include "Plex/PlexRawChannelToPinDiode.h"
00048 #include "PulserCalibration/PulserRawDrift.h"
00049 #include "PulserCalibration/PulserRawDriftF.h"
00050 #include "PulserCalibration/PulserRefDrift.h"
00051 #include "PulserCalibration/PulserRefDriftF.h"
00052 #include "PulserCalibration/PulserRawDriftPin.h"
00053 #include "PulserCalibration/PulserRefDriftPin.h"
00054 #include "PulserCalibration/PulserRawGain.h"
00055 #include "RawData/RawChannelId.h"
00056 #include "Validity/VldContext.h"
00057 #include "Validity/VldTimeStamp.h"
00058
00059 #include "LISummary/LIPlexMaps.h"
00060 #include "LISummary/LIPmt.h"
00061 #include "LISummary/LIRun.h"
00062
00063 CVSID("$Id: LIPlexMaps.cxx,v 1.72 2009/07/05 10:13:16 djauty Exp $");
00064
00065 ClassImp(LIPlexMaps)
00066
00067
00068
00069 class LedIdList : public std::vector<PlexLedId>
00070 {
00071
00072 public:
00073
00074 LedIdList(const VldContext& context) { Reset(context);};
00075 LedIdList() {
00076 VldTimeStamp ts;
00077 VldContext cx(Detector::kCalDet,SimFlag::kData,ts);
00078 Reset(cx);
00079 };
00080
00081 void Reset(const VldContext& context) {
00082 Int_t numRows=fResPtr.NewQuery(context,0);
00083 MSG("LIPlexMaps",Msg::kInfo)
00084 <<"New DB query produced "<<numRows<<" rows"<<endl;
00085 std::map<PlexLedId,int> tmpMap;
00086
00087 for (UInt_t i=0;i<fResPtr.GetNumRows();i++) {
00088 const PlexPinDiodeToLed* datum = fResPtr.GetRow(i);
00089 if(datum){
00090 tmpMap[datum->GetPlexLedId()] += 1;
00091 }
00092 }
00093
00094 this->clear();
00095 for (std::map<PlexLedId,int>::iterator it=tmpMap.begin();
00096 it!=tmpMap.end(); it++) {
00097 this->push_back(it->first);
00098 }
00099 };
00100
00101 private:
00102
00103 DbiResultPtr<PlexPinDiodeToLed> fResPtr;
00104
00105 };
00106
00107
00108
00109 LIPlexMaps::LIPlexMaps()
00110 {
00111 MSG("LIPlexMaps",Msg::kDebug)<<"LIPlexMaps Constructor"<<endl;
00112
00113
00114 gStyle->SetPalette(1,(Int_t*)0);
00115
00116 }
00117
00118
00119
00120 LIPlexMaps::~LIPlexMaps()
00121 {
00122 MSG("LIPlexMaps",Msg::kDebug)<<"LIPlexMaps Destructor"<<endl;
00123 }
00124
00125
00126
00127 Bool_t LIPlexMaps::IsPermitted() const
00128 {
00129 MSG("LIPlexMaps",Msg::kDebug)
00130 <<" ** Running IsPermitted method... **"<<endl;
00131
00132 char* envVariable=getenv("LITSQLPERMISSION");
00133 if (envVariable==NULL){
00134 MSG("LIAnalysis",Msg::kWarning)
00135 <<endl<<endl
00136 <<"*************************************************************"
00137 <<endl
00138 <<"WARNING: You have tried to do a sensitive operation."<<endl
00139 <<"This feature is designed to make you stop and think."<<endl
00140 <<"If you know what you are doing then look at the code."<<endl
00141 <<"*************************************************************"
00142 <<endl<<endl;
00143 return false;
00144 }
00145
00146 MSG("LIPlexMaps",Msg::kDebug)
00147 <<" ** Finished IsPermitted method **"<<endl;
00148 return true;
00149 }
00150
00151
00152
00153 void LIPlexMaps::ScaleVector(vector<Double_t>& v,Double_t scaleFactor)
00154 {
00155 MSG("LIPlexMaps",Msg::kDebug)
00156 <<" ** Running ScaleVector method... **"<<endl;
00157
00158 for (UInt_t i=0;i<v.size();i++) v[i]*=scaleFactor;
00159
00160 MSG("LIPlexMaps",Msg::kDebug)
00161 <<" ** Finished ScaleVector method **"<<endl;
00162 }
00163
00164
00165
00166 void LIPlexMaps::NormaliseVector(vector<Double_t>& v,Int_t mode)
00167 {
00168 MSG("LIPlexMaps",Msg::kDebug)
00169 <<" ** Running NormaliseVector method... **"<<endl;
00170
00171 if (v.size()>0){
00172
00173 if (mode==1){
00174
00175 Double_t average=0;
00176 for (UInt_t i=0;i<v.size();i++) average+=v[i];
00177 average/=v.size();
00178
00179 MSG("LIPlexMaps",Msg::kVerbose)<<"Average="<<average<<endl;
00180
00181
00182 for (UInt_t i=0;i<v.size();i++) v[i]/=average;
00183 }
00184 else if (mode==2){
00185
00186 Double_t vMax=-9e50;
00187 Double_t vMin=9e50;
00188
00189
00190 for (UInt_t i=0;i<v.size();i++){
00191 if (v[i]>vMax) vMax=v[i];
00192 if (v[i]<vMin) vMin=v[i];
00193 }
00194
00195
00196 Int_t numBins=300;
00197 if (4*v.size()<10000) numBins=4*v.size();
00198
00199 MSG("LIAnalysis",Msg::kInfo)
00200 <<"vMax="<<vMax <<", vMin="<<vMin<<", numBins="<<numBins<<endl;
00201
00202
00203
00204 TH1F* h=new TH1F("h","h",numBins,vMin-fabs(0.1*vMin),
00205 vMax+fabs(0.1*vMin));
00206 h->SetBit(TH1::kCanRebin);
00207
00208 Double_t average=0;
00209 for (UInt_t i=0;i<v.size();i++){
00210
00211 average+=v[i];
00212
00213
00214 h->Fill(v[i]);
00215 }
00216 average/=v.size();
00217
00218
00219 h->Fit("gaus","q0");
00220 TF1* func=h->GetFunction("gaus");
00221 Double_t p1=func->GetParameter(1);
00222 Double_t p2=func->GetParameter(2);
00223
00224
00225 Double_t avToNormWith=p1;
00226 if (p1<vMin || p1>vMax) avToNormWith=average;
00227
00228 MSG("LIAnalysis",Msg::kInfo)
00229 <<"Fitted mean="<<p1
00230 <<" (average="<<average
00231 <<") fitted rms="<<p2
00232 <<", using avToNormWith="<<avToNormWith<<endl;
00233
00234
00235 for (UInt_t i=0;i<v.size();i++) v[i]/=avToNormWith;
00236
00237 delete h;
00238 }
00239 }
00240
00241 MSG("LIPlexMaps",Msg::kDebug)
00242 <<" ** Finished NormaliseVector method **"<<endl;
00243 }
00244
00245
00246
00247 void LIPlexMaps::BinomialGen(vector<Double_t>& v,Int_t N,Double_t p)
00248 {
00249 MSG("LIPlexMaps",Msg::kDebug)
00250 <<" ** Running BinomialGen method... **"<<endl;
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 Double_t totalProb=0;
00262
00263 if (N<=170){
00264 vector<Double_t> factorials(N+1);
00265 this->FactorialGen(factorials);
00266
00267 for (UInt_t r=0;r<v.size();r++){
00268 Double_t perm=factorials[N]/(factorials[r]*factorials[N-r]);
00269 Double_t successes=pow(p,(Int_t)(r));
00270 Double_t failures=pow(1-p,(Int_t)(N-r));
00271 v[r]=perm*successes*failures;
00272 totalProb+=v[r];
00273 MSG("LIPlexMaps",Msg::kInfo)
00274 <<"Prob of "<<r<<" events = "<<v[r]
00275 <<" (perm="<<perm
00276 <<", succ="<<successes
00277 <<", fail="<<failures<<")"
00278 <<endl;
00279
00280 MSG("LIPlexMaps",Msg::kInfo)<<"Total prob = "<<totalProb<<endl;
00281 }
00282 }
00283 else if (N>170){
00284
00285
00286
00287 MSG("LIPlexMaps",Msg::kInfo)
00288 <<"Above N=170 this has not been implemented"<<endl;
00289 }
00290
00291 MSG("LIPlexMaps",Msg::kDebug)
00292 <<" ** Finished BinomialGen method **"<<endl;
00293 }
00294
00295
00296
00297 void LIPlexMaps::FactorialGen(vector<Double_t>& v)
00298 {
00299 MSG("LIPlexMaps",Msg::kDebug)
00300 <<" ** Running FactorialGen method... **"<<endl;
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 if (v.size()>=2){
00311 v[0]=1;
00312 v[1]=1;
00313 }
00314
00315 for (UInt_t i=2;i<v.size();i++){
00316 v[i]=v[i-1]*i;
00317 MSG("LIPlexMaps",Msg::kInfo)<<i<<" factorial = "<<v[i]<<endl;
00318 }
00319
00320 MSG("LIPlexMaps",Msg::kDebug)
00321 <<" ** Finished FactorialGen method **"<<endl;
00322 }
00323
00324
00325
00326 Int_t LIPlexMaps::SampleDist(vector<Double_t> v,TRandom* tRand)
00327 {
00328 MSG("LIPlexMaps",Msg::kVerbose)
00329 <<" ** Running SampleDist method... **"<<endl;
00330
00331
00332
00333 Int_t size=v.size();
00334 Int_t p=-1;
00335
00336 Int_t foundPoint=0;
00337 while (foundPoint==0){
00338
00339 p=tRand->Integer(size);
00340 Double_t probToChose=v[p];
00341 Double_t r1=tRand->Rndm();
00342
00343 MSG("LIPlexMaps",Msg::kVerbose)
00344 <<"point="<<p<<", probToChose="<<probToChose<<", r1="<<r1<<endl;
00345
00346 if (probToChose>=r1) foundPoint=1;
00347 }
00348
00349 MSG("LIPlexMaps",Msg::kVerbose)
00350 <<" ** Finished SampleDist method **"<<endl;
00351 return p;
00352 }
00353
00354
00355
00356 void LIPlexMaps::Attenuation()
00357 {
00358 MSG("LIPlexMaps",Msg::kInfo)
00359 <<" ** Running Attenuation method... **"<<endl;
00360
00361 vector<Double_t> x;
00362 vector<Double_t> xNorm;
00363 vector<Double_t> yGreenAtt1;
00364 vector<Double_t> yGreenAtt2;
00365 vector<Double_t> yGreen;
00366 vector<Double_t> yClear;
00367 vector<Double_t> y12C;
00368 vector<Double_t> y6G;
00369 vector<Double_t> y2G;
00370 vector<Double_t> y1G_12C_1G_1;
00371 vector<Double_t> y1G_12C_1G_2;
00372 vector<Double_t> y1G_12C_1G_3;
00373 vector<Double_t> x1G_12C_1G_1;
00374 vector<Double_t> x1G_12C_1G_2;
00375 vector<Double_t> x1G_12C_1G_3;
00376 vector<Double_t> y8G;
00377 vector<Double_t> y3GNear;
00378 vector<Double_t> y6CNear;
00379 vector<Double_t> y3GFar;
00380 vector<Double_t> y6CFar;
00381
00382 vector<Double_t> boost12C;
00383 vector<Double_t> boost6G;
00384 vector<Double_t> boost8G;
00385 vector<Double_t> boost1G_12C_1G;
00386 vector<Double_t> reflectivity;
00387
00388 Double_t maxCableLength=20;
00389 Int_t numPoints=1000;
00390
00391
00392 Double_t greenAtt1=1;
00393 Double_t greenAtt2=10;
00394 Double_t clearAtt=12;
00395
00396
00397
00398
00399
00400
00401 Double_t ref=1.0;
00402
00403 Double_t ref12C=exp(-12./clearAtt);
00404 Double_t ref6G=0.5*(exp(-6./greenAtt1)+exp(-6./greenAtt2));
00405 Double_t ref2G=0.5*(exp(-2./greenAtt1)+exp(-2./greenAtt2));
00406 Double_t ref8G=0.5*(exp(-8./greenAtt1)+exp(-8./greenAtt2));
00407 Double_t ref1G_12C_1G=ref2G*ref12C;
00408
00409 MSG("LIPlexMaps",Msg::kInfo)
00410 <<"Reflectivity = "<<ref
00411 <<endl
00412 <<"6m green = "<<ref6G<<" (0.22)"
00413 <<endl
00414 <<"12m clear = "<<ref12C<<" (0.20)"
00415 <<endl
00416 <<"8m green = "<<ref8G<<" (0.06)"
00417 <<endl
00418 <<"1mG & 12mC & 1mG = "<<ref1G_12C_1G<<" (0.09)"
00419 <<endl;
00420
00421 MSG("LIPlexMaps",Msg::kInfo)
00422 <<"Calculating boosts..."<<endl;
00423 for (Int_t i=0;i<numPoints;i++){
00424 reflectivity.push_back(0);
00425 boost12C.push_back(0);
00426 boost6G.push_back(0);
00427 boost1G_12C_1G.push_back(0);
00428 boost8G.push_back(0);
00429
00430 Double_t connectorEff=1.0;
00431
00432 reflectivity[i]=i*1./numPoints;
00433 boost12C[i]=connectorEff*reflectivity[i]*ref12C;
00434 boost1G_12C_1G[i]=connectorEff*reflectivity[i]*ref12C*ref2G;
00435
00436 boost6G[i]=reflectivity[i]*ref6G;
00437 boost8G[i]=reflectivity[i]*ref8G;
00438 }
00439
00440 MSG("LIPlexMaps",Msg::kInfo)
00441 <<"Calculating basic attenuation curves..."<<endl;
00442 for (Int_t i=0;i<numPoints;i++){
00443 x.push_back(0);
00444 yGreenAtt1.push_back(0);
00445 yGreenAtt2.push_back(0);
00446 yGreen.push_back(0);
00447 yClear.push_back(0);
00448
00449 x[i]=i*maxCableLength/numPoints;
00450 yGreenAtt1[i]=exp(-x[i]/greenAtt1);
00451 yGreenAtt2[i]=exp(-x[i]/greenAtt2);
00452 yGreen[i]=0.5*(exp(-x[i]/greenAtt1)+exp(-x[i]/greenAtt2));
00453 yClear[i]=exp(-x[i]/clearAtt);
00454 }
00455
00456 MSG("LIPlexMaps",Msg::kInfo)
00457 <<"Calculating for 1st 1 m of green..."<<endl;
00458 for (Int_t i=0;i<numPoints;i++){
00459 Double_t x=i*1./numPoints;
00460 xNorm.push_back(0);
00461 y12C.push_back(0);
00462 y6G.push_back(0);
00463 y2G.push_back(0);
00464 y8G.push_back(0);
00465
00466
00467 xNorm[i]=i*1./numPoints;
00468
00469 y12C[i]=exp(-12*xNorm[i]/clearAtt);
00470 y6G[i]=0.5*(exp(-6*xNorm[i]/greenAtt1)+exp(-6*xNorm[i]/greenAtt2));
00471 y2G[i]=0.5*(exp(-2*xNorm[i]/greenAtt1)+exp(-2*xNorm[i]/greenAtt2));
00472
00473 if (x<1./14){
00474 Double_t x2=i*1./((1./14)*numPoints);
00475 y1G_12C_1G_1.push_back(0);
00476 x1G_12C_1G_1.push_back(0);
00477 x1G_12C_1G_1[i]=x;
00478 y1G_12C_1G_1[i]=0.5*(exp(-1*x2/greenAtt1)+exp(-1*x2/greenAtt2));
00479 MSG("LIPlexMaps",Msg::kDebug)
00480 <<"x="<<x<<", x2="<<x2
00481 <<", x1G_12C_1G_1[i]="<<x1G_12C_1G_1[i]
00482 <<", y1G_12C_1G_1[i]="<<y1G_12C_1G_1[i]
00483 <<endl;
00484 }
00485 y8G[i]=0.5*(exp(-8*xNorm[i]/greenAtt1)+exp(-8*xNorm[i]/greenAtt2));
00486 }
00487
00488 UInt_t size_1=y1G_12C_1G_1.size();
00489 Int_t counter=0;
00490
00491 MSG("LIPlexMaps",Msg::kInfo)
00492 <<"Calculating for 12 m of clear..."<<endl;
00493 for (Int_t i=0;i<numPoints;i++){
00494 Double_t x=i*1./numPoints;
00495
00496 if (x>1./14 && x<13./14){
00497 Double_t x2=counter*1./((12./14)*numPoints);
00498 y1G_12C_1G_2.push_back(0);
00499 x1G_12C_1G_2.push_back(0);
00500 x1G_12C_1G_2[counter]=x;
00501 y1G_12C_1G_2[counter]=y1G_12C_1G_1[size_1-1]*exp(-12*x2/clearAtt);
00502 MSG("LIPlexMaps",Msg::kDebug)
00503 <<"x="<<x<<", x2="<<x2
00504 <<", x1G_12C_1G_2[i]="<<x1G_12C_1G_2[counter]
00505 <<", y1G_12C_1G_2[i]="<<y1G_12C_1G_2[counter]
00506 <<endl;
00507 counter++;
00508 }
00509 }
00510
00511 UInt_t size_2=y1G_12C_1G_2.size();
00512 counter=0;
00513
00514 MSG("LIPlexMaps",Msg::kInfo)
00515 <<"Calculating for last 1 m of green..."<<endl;
00516 for (Int_t i=0;i<numPoints;i++){
00517 Double_t x=i*1./numPoints;
00518
00519 if (x>13./14){
00520 Double_t x2=counter*1./((1./14)*numPoints);
00521 y1G_12C_1G_3.push_back(0);
00522 x1G_12C_1G_3.push_back(0);
00523 x1G_12C_1G_3[counter]=x;
00524
00525
00526 Double_t scaleFactor=1./y1G_12C_1G_1[size_1-1];
00527 y1G_12C_1G_3[counter]=scaleFactor*y1G_12C_1G_2[size_2-1]*0.5*
00528 (exp(-1*(x2+1)/greenAtt1)+
00529 exp(-1*(x2+1)/greenAtt2));
00530 MSG("LIPlexMaps",Msg::kDebug)
00531 <<"x="<<x<<", x2="<<x2
00532 <<", x1G_12C_1G_3[i]="<<x1G_12C_1G_3[counter]
00533 <<", y1G_12C_1G_3[i]="<<y1G_12C_1G_3[counter]
00534 <<endl;
00535 counter++;
00536 }
00537 }
00538
00539 UInt_t size_3=y1G_12C_1G_3.size();
00540 UInt_t size_8G=y8G.size();
00541
00542 MSG("LIPlexMaps",Msg::kInfo)
00543 <<"Calculating for last section to PMT..."<<endl;
00544 MSG("LIPlexMaps",Msg::kInfo)
00545 <<"Near side..."<<endl;
00546 for (Int_t i=0;i<numPoints;i++){
00547 Double_t x=i*1./numPoints;
00548
00549 y3GNear.push_back(0);
00550 y6CNear.push_back(0);
00551
00552 y3GNear[i]=y1G_12C_1G_3[size_3-1]*0.5*
00553 (exp(-3.*x/greenAtt1)+exp(-3.*x/greenAtt2));
00554 y6CNear[i]=y8G[size_8G-1]*exp(-6.*x/clearAtt);
00555
00556 MSG("LIPlexMaps",Msg::kDebug)
00557 <<"x="<<x
00558 <<", y3GNear[i]="<<y3GNear[i]
00559 <<", y6CNear[i]"<<y6CNear[i]
00560 <<endl;
00561 }
00562
00563 UInt_t size_12C=y12C.size();
00564 UInt_t size_6G=y6G.size();
00565
00566 MSG("LIPlexMaps",Msg::kInfo)
00567 <<"Far side..."<<endl;
00568 for (Int_t i=0;i<numPoints;i++){
00569 Double_t x=i*1./numPoints;
00570
00571 y3GFar.push_back(0);
00572 y6CFar.push_back(0);
00573
00574 y3GFar[i]=y12C[size_12C-1]*0.5*
00575 (exp(-3.*x/greenAtt1)+exp(-3.*x/greenAtt2));
00576 y6CFar[i]=y6G[size_6G-1]*exp(-6.*x/clearAtt);
00577
00578 MSG("LIPlexMaps",Msg::kDebug)
00579 <<"x="<<x
00580 <<", y3GFar[i]="<<y3GFar[i]
00581 <<", y6CFar[i]"<<y6CFar[i]
00582 <<endl;
00583 }
00584
00585
00586 TCanvas *cAttenuation=new TCanvas("cAttenuation","cAttenuation",
00587 1,1,1000,800);
00588 cAttenuation->SetFillColor(0);
00589 cAttenuation->Divide(2,2);
00590
00591
00592 TGraph* gGreen=TGraphVect(x,yGreen);
00593 gGreen->SetTitle("Green Attenuation length (1+2)");
00594 gGreen->SetMarkerStyle(3);
00595 gGreen->SetMarkerColor(3);
00596 gGreen->SetMarkerSize(0.2);
00597 cAttenuation->cd(1);
00598 gGreen->Draw("AP");
00599 gGreen->GetXaxis()->SetTitle("Cable length");
00600 gGreen->GetYaxis()->SetTitle("Intensity");
00601 gGreen->GetXaxis()->CenterTitle();
00602 gGreen->GetYaxis()->CenterTitle();
00603 gGreen->SetMinimum(0);
00604
00605
00606 TGraph* gGreenAtt1=TGraphVect(x,yGreenAtt1);
00607 gGreenAtt1->SetTitle("Green Attenuation length 1");
00608 gGreenAtt1->SetMarkerStyle(3);
00609 gGreenAtt1->SetMarkerColor(30);
00610 gGreenAtt1->SetMarkerSize(0.2);
00611 cAttenuation->cd(2);
00612 gGreenAtt1->Draw("AP");
00613 gGreenAtt1->GetXaxis()->SetTitle("Cable length");
00614 gGreenAtt1->GetYaxis()->SetTitle("Intensity");
00615 gGreenAtt1->GetXaxis()->CenterTitle();
00616 gGreenAtt1->GetYaxis()->CenterTitle();
00617 gGreenAtt1->SetMinimum(0);
00618
00619
00620 TGraph* gGreenAtt2=TGraphVect(x,yGreenAtt2);
00621 gGreenAtt2->SetTitle("Green Attenuation length 2");
00622 gGreenAtt2->SetMarkerStyle(3);
00623 gGreenAtt2->SetMarkerColor(8);
00624 gGreenAtt2->SetMarkerSize(0.2);
00625 cAttenuation->cd(3);
00626 gGreenAtt2->Draw("AP");
00627 gGreenAtt2->GetXaxis()->SetTitle("Cable length");
00628 gGreenAtt2->GetYaxis()->SetTitle("Intensity");
00629 gGreenAtt2->GetXaxis()->CenterTitle();
00630 gGreenAtt2->GetYaxis()->CenterTitle();
00631 gGreenAtt2->SetMinimum(0);
00632
00633
00634 TGraph* gClear=TGraphVect(x,yClear);
00635 gClear->SetTitle("Clear Attenuation length");
00636 gClear->SetMarkerStyle(3);
00637 gClear->SetMarkerColor(1);
00638 gClear->SetMarkerSize(0.2);
00639 cAttenuation->cd(4);
00640 gClear->Draw("AP");
00641 gClear->GetXaxis()->SetTitle("Cable length");
00642 gClear->GetYaxis()->SetTitle("Intensity");
00643 gClear->GetXaxis()->CenterTitle();
00644 gClear->GetYaxis()->CenterTitle();
00645 gClear->SetMinimum(0);
00646
00648
00650 MSG("LIPlexMaps",Msg::kInfo)
00651 <<"Drawing cAttCalDet canvas..."<<endl;
00652 TCanvas *cAttCalDet=new TCanvas("cAttCalDet","cAttCalDet",
00653 1,1,1000,800);
00654 cAttCalDet->SetFillColor(0);
00655
00656
00657
00658 TGraph* g12C=TGraphVect(xNorm,y12C);
00659 g12C->SetTitle("Fractional Attenuation (LI Far Side)");
00660 g12C->SetMarkerStyle(3);
00661 g12C->SetMarkerColor(1);
00662 g12C->SetMarkerSize(0.2);
00663 cAttCalDet->cd(1);
00664 g12C->Draw("AP");
00665 g12C->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00666 g12C->GetYaxis()->SetTitle("Intensity");
00667 g12C->GetXaxis()->CenterTitle();
00668 g12C->GetYaxis()->CenterTitle();
00669 g12C->SetMinimum(0);
00670
00671
00672 TGraph* g6G=TGraphVect(xNorm,y6G);
00673 g6G->SetTitle("Fractional Attenuation");
00674 g6G->SetMarkerStyle(3);
00675 g6G->SetMarkerColor(3);
00676 g6G->SetMarkerSize(0.2);
00677 cAttCalDet->cd(1);
00678 g6G->Draw("P");
00679
00680
00681 TGraph* g12C_2=TGraphVect(xNorm,y12C);
00682 g12C_2->SetTitle("12 m Clear Attenuation");
00683 g12C_2->SetMarkerStyle(3);
00684 g12C_2->SetMarkerColor(1);
00685 g12C_2->SetMarkerSize(0.2);
00686
00687
00688 g12C_2->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00689 g12C_2->GetYaxis()->SetTitle("Intensity");
00690 g12C_2->GetXaxis()->CenterTitle();
00691 g12C_2->GetYaxis()->CenterTitle();
00692 g12C_2->SetMinimum(0);
00693
00694
00695 g6G->SetTitle("6 m Green Attenuation");
00696 g6G->SetMarkerStyle(3);
00697 g6G->SetMarkerColor(3);
00698 g6G->SetMarkerSize(0.2);
00699
00700
00701 g6G->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00702 g6G->GetYaxis()->SetTitle("Intensity");
00703 g6G->GetXaxis()->CenterTitle();
00704 g6G->GetYaxis()->CenterTitle();
00705 g6G->SetMinimum(0);
00706
00708
00710 MSG("LIPlexMaps",Msg::kInfo)
00711 <<"Drawing cAttCalDet2 canvas..."<<endl;
00712 TCanvas *cAttCalDet2=new TCanvas("cAttCalDet2","cAttCalDet2",
00713 1,1,1000,800);
00714 cAttCalDet2->SetFillColor(0);
00715 cAttCalDet2->Divide(1,1);
00716
00717
00718 TGraph* gDummy=TGraphVect(xNorm,xNorm);
00719 gDummy->SetTitle("Fractional Attenuation (LI Near Side)");
00720 gDummy->SetMinimum(0);
00721 gDummy->SetMaximum(1.2);
00722 gDummy->SetMarkerColor(0);
00723 cAttCalDet2->cd(1);
00724 gDummy->Draw("AP");
00725 gDummy->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00726 gDummy->GetYaxis()->SetTitle("Intensity");
00727 gDummy->GetXaxis()->CenterTitle();
00728 gDummy->GetYaxis()->CenterTitle();
00729
00730
00731 TGraph* g1G_12C_1G_1=TGraphVect(x1G_12C_1G_1,y1G_12C_1G_1);
00732 g1G_12C_1G_1->SetTitle("Fractional Attenuation");
00733 g1G_12C_1G_1->SetMarkerStyle(3);
00734 g1G_12C_1G_1->SetMarkerColor(3);
00735 g1G_12C_1G_1->SetMarkerSize(0.2);
00736 cAttCalDet2->cd(1);
00737 g1G_12C_1G_1->Draw("p");
00738 g1G_12C_1G_1->SetMinimum(0);
00739
00740
00741 TGraph* g1G_12C_1G_2=TGraphVect(x1G_12C_1G_2,y1G_12C_1G_2);
00742 g1G_12C_1G_2->SetTitle("Fractional Attenuation");
00743 g1G_12C_1G_2->SetMarkerStyle(3);
00744 g1G_12C_1G_2->SetMarkerColor(1);
00745 g1G_12C_1G_2->SetMarkerSize(0.2);
00746 cAttCalDet2->cd(1);
00747 g1G_12C_1G_2->Draw("P");
00748 g1G_12C_1G_2->SetMinimum(0);
00749
00750
00751 TGraph* g1G_12C_1G_3=TGraphVect(x1G_12C_1G_3,y1G_12C_1G_3);
00752 g1G_12C_1G_3->SetTitle("Fractional Attenuation");
00753 g1G_12C_1G_3->SetMarkerStyle(3);
00754 g1G_12C_1G_3->SetMarkerColor(3);
00755 g1G_12C_1G_3->SetMarkerSize(0.2);
00756 cAttCalDet2->cd(1);
00757 g1G_12C_1G_3->Draw("P");
00758 g1G_12C_1G_3->SetMinimum(0);
00759
00760
00761 TGraph* g8G=TGraphVect(xNorm,y8G);
00762 g8G->SetTitle("Fractional Attenuation");
00763 g8G->SetMarkerStyle(3);
00764 g8G->SetMarkerColor(8);
00765 g8G->SetMarkerSize(0.2);
00766 cAttCalDet2->cd(1);
00767 g8G->Draw("P");
00768 g8G->SetMinimum(0);
00769
00771
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00807
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00843
00845 MSG("LIPlexMaps",Msg::kInfo)
00846 <<"Drawing cBoostsFar canvas..."<<endl;
00847 TCanvas *cBoostsFar=new TCanvas("cBoostsFar","cBoostsFar",
00848 1,1,1000,800);
00849 cBoostsFar->SetFillColor(0);
00850 cBoostsFar->Divide(1,1);
00851
00852
00853 TGraph* cBoost6G=TGraphVect(reflectivity,boost6G);
00854 cBoost6G->SetTitle("Fractional Boost vs Reflectivity");
00855 cBoost6G->SetMarkerStyle(3);
00856 cBoost6G->SetMarkerColor(3);
00857 cBoost6G->SetMarkerSize(0.2);
00858 cBoostsFar->cd(1);
00859 cBoost6G->Draw("AP");
00860 cBoost6G->GetXaxis()->SetTitle("Reflectivity");
00861 cBoost6G->GetYaxis()->SetTitle("Fractional Boost");
00862 cBoost6G->GetXaxis()->CenterTitle();
00863 cBoost6G->GetYaxis()->CenterTitle();
00864 cBoost6G->SetMaximum(1.2);
00865 cBoost6G->SetMinimum(0);
00866
00867
00868 TGraph* cBoost12C=TGraphVect(reflectivity,boost12C);
00869 cBoost12C->SetTitle("Fractional Boost vs Reflectivity");
00870 cBoost12C->SetMarkerStyle(3);
00871 cBoost12C->SetMarkerColor(1);
00872 cBoost12C->SetMarkerSize(0.2);
00873 cBoostsFar->cd(1);
00874 cBoost12C->Draw("P");
00875 cBoost12C->SetMinimum(0);
00876
00877
00879
00881 MSG("LIPlexMaps",Msg::kInfo)
00882 <<"Drawing cBoostsNear canvas..."<<endl;
00883 TCanvas *cBoostsNear=new TCanvas("cBoostsNear","cBoostsNear",
00884 1,1,1000,800);
00885 cBoostsNear->SetFillColor(0);
00886 cBoostsNear->Divide(1,1);
00887
00888
00889 TGraph* cBoost8G=TGraphVect(reflectivity,boost8G);
00890 cBoost8G->SetTitle("Fractional Boost vs Reflectivity");
00891 cBoost8G->SetMarkerStyle(3);
00892 cBoost8G->SetMarkerColor(3);
00893 cBoost8G->SetMarkerSize(0.2);
00894 cBoostsNear->cd(1);
00895 cBoost8G->Draw("AP");
00896 cBoost8G->GetXaxis()->SetTitle("Reflectivity");
00897 cBoost8G->GetYaxis()->SetTitle("Fractional Boost");
00898 cBoost8G->GetXaxis()->CenterTitle();
00899 cBoost8G->GetYaxis()->CenterTitle();
00900 cBoost8G->SetMaximum(1.2);
00901 cBoost8G->SetMinimum(0);
00902
00903
00904 TGraph* cBoost1G_12C_1G=TGraphVect(reflectivity,boost1G_12C_1G);
00905 cBoost1G_12C_1G->SetTitle("Fractional Boost vs Reflectivity");
00906 cBoost1G_12C_1G->SetMarkerStyle(3);
00907 cBoost1G_12C_1G->SetMarkerColor(1);
00908 cBoost1G_12C_1G->SetMarkerSize(0.2);
00909 cBoostsNear->cd(1);
00910 cBoost1G_12C_1G->Draw("P");
00911 cBoost1G_12C_1G->SetMinimum(0);
00912
00913 MSG("LIPlexMaps",Msg::kInfo)
00914 <<" ** Finished Attenuation method **"<<endl;
00915 }
00916
00917
00918
00919 void LIPlexMaps::ADCRailEffect()
00920 {
00921 MSG("LIPlexMaps",Msg::kInfo)
00922 <<" ** Running ADCRailEffect method... **"<<endl;
00923
00925
00927
00928
00929
00930
00931
00932
00933
00934 gStyle->SetPalette(1);
00935
00936 gStyle->SetOptStat(1111111);
00937
00938 TStopwatch stopwatch;
00939
00940
00941 const Double_t kQE=0.13;
00942
00943
00944
00945
00946
00947
00948 const Int_t kNumBinomPoints=static_cast<Int_t>(1e6);
00949
00950 MSG("LIPlexMaps",Msg::kInfo)
00951 <<endl<<"The following parameters are used in the MC:"<<endl
00952 <<"kQE="<<kQE<<endl
00953 <<"kNumBinomPoints="<<kNumBinomPoints<<endl;
00954
00955 Int_t maxN=150;
00956 TH1F *hBinomial= new TH1F("hBinomial","Binomial distribution",
00957 maxN+5,-1,maxN+4);
00958 hBinomial->SetFillColor(0);
00959 hBinomial->SetBit(TH1::kCanRebin);
00960
00961 TH1F *hBinomial2= new TH1F("hBinomial2","Binomial distribution",
00962 maxN+5,-1,maxN+4);
00963 hBinomial2->SetFillColor(0);
00964 hBinomial2->SetLineColor(2);
00965 hBinomial2->SetBit(TH1::kCanRebin);
00966
00967 TH1F *hBinomial3= new TH1F("hBinomial3","Binomial distribution",
00968 maxN+5,-1,maxN+4);
00969 hBinomial3->SetFillColor(0);
00970 hBinomial3->SetLineColor(3);
00971 hBinomial3->SetBit(TH1::kCanRebin);
00972
00973
00974 TRandom *tRandom=new TRandom(0);
00975
00976 for (Int_t N=100;N<160;N+=20){
00977 static Int_t counter=0;
00978 counter++;
00979
00980 MSG("LIPlexMaps",Msg::kInfo)
00981 <<endl<<"Generating binomial distribution..."<<endl;
00982 for (Int_t i=0;i<kNumBinomPoints;i++){
00983
00984
00985
00986 Int_t r1=tRandom->Binomial(static_cast<Int_t>(N),
00987 static_cast<Double_t>(kQE));
00988
00989
00990 if (r1>15) r1=15;
00991
00992 if (counter==1) hBinomial->Fill(r1);
00993 if (counter==2) hBinomial2->Fill(r1);
00994 if (counter==3) hBinomial3->Fill(r1);
00995
00996
00997 Float_t fract=ceil(kNumBinomPoints/5.);
00998 if (ceil(((Float_t)i)/fract)==((Float_t)i)/fract){
00999 MSG("LIPlexMaps",Msg::kInfo)
01000 <<"Fraction of loop complete: "<<i
01001 <<"/"<<kNumBinomPoints<<" ("
01002 <<(Int_t)(100.*i/kNumBinomPoints)<<"%)"<<endl;
01003 }
01004 }
01005 MSG("LIPlexMaps",Msg::kInfo)
01006 <<"Binomial distribution done"<<endl;
01007 }
01008
01009
01010 TCanvas *cBinomial=new TCanvas("cBinomial","cBinomial",1,1,1000,800);
01011 cBinomial->SetFillColor(0);
01012 cBinomial->cd();
01013 hBinomial->Draw();
01014 hBinomial2->Draw("sames");
01015 hBinomial3->Draw("sames");
01016
01017 MSG("LIPlexMaps",Msg::kInfo)
01018 <<" ** Finished ADCRailEffect method **"<<endl;
01019 }
01020
01021
01022
01023 void LIPlexMaps::NonLinearity()
01024 {
01025 MSG("LIPlexMaps",Msg::kInfo)
01026 <<" ** Running NonLinearity method... **"<<endl;
01027
01028
01029 gStyle->SetPalette(1);
01030
01031 gStyle->SetOptStat(1111111);
01032
01033 Int_t maxN=1000;
01034
01035 TH1F *hBinomial= new TH1F("hBinomial","Binomial distribution",
01036 maxN+5,-1,maxN+4);
01037 hBinomial->SetFillColor(0);
01038 hBinomial->SetLineColor(3);
01039 hBinomial->SetBit(TH1::kCanRebin);
01040
01041 TH1F *hAdc= new TH1F("hAdc","Binomial distribution",
01042 60*maxN+5,-1,60*maxN+4);
01043 hAdc->SetFillColor(0);
01044 hAdc->SetLineColor(3);
01045 hAdc->SetBit(TH1::kCanRebin);
01046
01047 TH1F *hGauss= new TH1F("hGauss","Binomial distribution",
01048 maxN+5,-1,maxN+4);
01049 hGauss->SetFillColor(0);
01050 hGauss->SetLineColor(2);
01051 hGauss->SetBit(TH1::kCanRebin);
01052
01053
01054 TRandom *tRandom=new TRandom(0);
01055
01056 Int_t kNumBinomPoints=10000;
01057 vector<Double_t> vPe;
01058 vector<Double_t> vAdc;
01059
01060 for (Int_t N=120;N<270;N+=2){
01061 static Int_t counter=0;
01062 counter++;
01063
01064 hBinomial->Reset();
01065 hAdc->Reset();
01066 hGauss->Reset();
01067
01068 MSG("LIPlexMaps",Msg::kInfo)
01069 <<endl<<"Generating distribution, N="<<N<<endl;
01070 for (Int_t i=0;i<kNumBinomPoints;i++){
01071
01072 Double_t gauss=tRandom->Gaus(1.*N,sqrt(1.*N));
01073 hGauss->Fill(gauss);
01074
01075 Double_t adc=70.*gauss-(1.3e-6*pow(1.*gauss,4.));
01076
01077
01078 if (gauss>237) adc=70*237-(1.3e-6*pow(237,4.));
01079
01080 hAdc->Fill(adc);
01081 }
01082
01083 vPe.push_back(1.*N);
01084 vAdc.push_back(hAdc->GetMean());
01085 }
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125 TCanvas *cBinomial=new TCanvas("cBinomial","cBinomial",1,1,1000,800);
01126 cBinomial->SetFillColor(0);
01127 cBinomial->cd();
01128 hBinomial->Draw();
01129 hGauss->Draw("sames");
01130
01131
01132 TCanvas *cAdc=new TCanvas("cAdc","cAdc",1,1,1000,800);
01133 cAdc->SetFillColor(0);
01134 cAdc->cd();
01135 hAdc->Draw();
01136
01137 vector<Double_t> vx;
01138 vector<Double_t> vy;
01139 vector<Double_t> vStraight;
01140
01141 for (Double_t i=0;i<300;i+=1){
01142 Double_t x=i;
01143 Double_t y=70*x-(1.3e-6*pow(x,4.));
01144
01145
01146 if (x>237) y=70*237-(1.3e-6*pow(237,4.));
01147
01148 vx.push_back(x);
01149 vy.push_back(y);
01150 vStraight.push_back(70*x);
01151
01152 }
01153
01154 TGraph* g=this->TGraphVect(vx,vy);
01155 TGraph* gStraight=this->TGraphVect(vx,vStraight);
01156 TGraph* gAdcVsPe=this->TGraphVect(vPe,vAdc);
01157
01158
01159 TCanvas *cNonLin=new TCanvas("cNonLin","cNonLin",1,1,1000,800);
01160 cNonLin->SetFillColor(0);
01161 cNonLin->cd();
01162 g->Draw("AP");
01163 g->SetMarkerSize(1);
01164 g->SetMarkerStyle(3);
01165 g->SetMarkerColor(3);
01166 gStraight->Draw("p");
01167 gStraight->SetMarkerSize(1);
01168 gStraight->SetMarkerStyle(3);
01169 gStraight->SetMarkerColor(1);
01170 gAdcVsPe->Draw("p");
01171 gAdcVsPe->SetMarkerSize(1);
01172 gAdcVsPe->SetMarkerStyle(3);
01173 gAdcVsPe->SetMarkerColor(2);
01174
01175
01176
01177
01178
01179 MSG("LIPlexMaps",Msg::kInfo)
01180 <<" ** Finished NonLinearity method **"<<endl;
01181 }
01182
01183
01184
01185 void LIPlexMaps::PeGen()
01186 {
01187 MSG("LIPlexMaps",Msg::kInfo)
01188 <<" ** Running PeGen method... **"<<endl;
01189
01191
01193
01194
01195
01196
01197
01198
01199
01200 gStyle->SetPalette(1);
01201
01202 gStyle->SetOptStat(1111111);
01203
01204 TStopwatch stopwatch;
01205
01206
01207 const Double_t kQE=0.13;
01208 const Double_t kGain=80;
01209
01210
01211
01212
01213 Double_t roughMean=500;
01214 Double_t roughRms=fLookup.CalcRms(roughMean,kGain,kQE);
01215 Double_t roughNpe=fLookup.CalcNpe(roughMean,roughRms,kQE);
01216
01217
01218 Double_t tempN=-1;
01219 Double_t rem=0;
01220 rem=modf(roughNpe/kQE,&tempN);
01221 if (rem>=0.5) tempN++;
01222
01223
01224
01225 const Int_t kN=static_cast<Int_t>(tempN);
01226 const Double_t kNpe=kN*kQE;
01227 const Double_t kMean=kGain*kNpe;
01228 const Double_t kRms=fLookup.CalcRms(kMean,kGain,kQE);
01229 const Double_t kAdcsPerPe=kMean/kNpe;
01230
01231
01232
01233
01234
01235
01236 const Int_t kNumBinomPoints=static_cast<Int_t>(1e6);
01237
01238 MSG("LIPlexMaps",Msg::kInfo)
01239 <<endl<<"The following parameters are used in the MC:"<<endl
01240 <<"kQE="<<kQE<<endl
01241 <<"kN="<<kN<<endl
01242 <<"kMean="<<kMean<<endl
01243 <<"kRms="<<kRms<<endl
01244 <<"kGain="<<kGain<<endl
01245 <<"kNpe="<<kNpe<<endl
01246 <<"kAdcsPerPe="<<kAdcsPerPe<<endl
01247 <<"kNumBinomPoints="<<kNumBinomPoints<<endl;
01248
01249 TH1F *hBinomial= new TH1F("hBinomial","Binomial distribution",
01250 kN+3,-1,kN+2);
01251 hBinomial->SetFillColor(0);
01252 hBinomial->SetBit(TH1::kCanRebin);
01253
01254 TH1F *hADC= new TH1F("hADC","hADC",15000,-1,15000);
01255 hADC->SetFillColor(0);
01256 hADC->SetBit(TH1::kCanRebin);
01257 TH1F *hADC2= new TH1F("hADC2","hADC2",15000,-1,15000);
01258 hADC2->SetFillColor(0);
01259 hADC2->SetBit(TH1::kCanRebin);
01260
01261 vector<Double_t> vBinomial(kN+1);
01262 Double_t maxInBinomial=0;
01263 Int_t maxInBinomialPos=0;
01264
01265
01266 TRandom *tRandom=new TRandom(0);
01267 MSG("LIPlexMaps",Msg::kInfo)
01268 <<endl<<"Generating binomial distribution..."<<endl;
01269 for (Int_t i=0;i<kNumBinomPoints;i++){
01270
01271
01272
01273 Int_t r1=tRandom->Binomial(static_cast<Int_t>(kN),
01274 static_cast<Double_t>(kQE));
01275 hBinomial->Fill(r1);
01276 vBinomial[r1]++;
01277
01278
01279 if (vBinomial[r1]>maxInBinomial){
01280 maxInBinomial=vBinomial[r1];
01281 maxInBinomialPos=r1;
01282 }
01283
01284
01285 Float_t fract=ceil(kNumBinomPoints/5.);
01286 if (ceil(((Float_t)i)/fract)==((Float_t)i)/fract){
01287 MSG("LIPlexMaps",Msg::kInfo)
01288 <<"Fraction of loop complete: "<<i
01289 <<"/"<<kNumBinomPoints<<" ("
01290 <<(Int_t)(100.*i/kNumBinomPoints)<<"%)"<<endl;
01291 }
01292 }
01293 MSG("LIPlexMaps",Msg::kInfo)
01294 <<"Binomial distribution done"<<endl;
01295
01296
01297 TCanvas *cBinomial=new TCanvas("cBinomial","cBinomial",1,1,1000,800);
01298 cBinomial->SetFillColor(0);
01299 cBinomial->cd();
01300 hBinomial->Draw();
01301
01302
01303 this->ScaleVector(vBinomial,1/maxInBinomial);
01304
01305
01306
01307 for (Int_t i=0;i<2500;i++){
01308 MSG("LIPlexMaps",Msg::kVerbose)<<"i="<<i<<endl;
01309 hADC->Fill(kAdcsPerPe*hBinomial->GetRandom());
01310 Int_t npe=this->SampleDist(vBinomial,tRandom);
01311 hADC2->Fill(kAdcsPerPe*npe);
01312 }
01313
01314
01315 TCanvas *cAdc=new TCanvas("cAdc","cAdc",1,1,1000,800);
01316 cAdc->SetFillColor(0);
01317 cAdc->Divide(2,1);
01318 cAdc->cd(1);
01319 hADC->Draw();
01320 cAdc->cd(2);
01321 hADC2->Draw();
01322
01323 const Int_t kNumPoints=20;
01324 const Int_t kFlashes=500;
01325 Double_t *numFlashes=new Double_t[kNumPoints];
01326
01327 MSG("LIPlexMaps",Msg::kInfo)
01328 <<endl<<"Calculating errors analytically"<<endl;
01329
01330 for (Int_t j=0;j<kNumPoints;j++){
01331 numFlashes[j]=static_cast<Double_t>((j+1)*kFlashes);
01332 MSG("LIPlexMaps",Msg::kInfo)
01333 <<endl<<"Point "<<j+1<<"/"<<kNumPoints
01334 <<", numFlashes="<<numFlashes[j]<<endl;
01335
01336
01337
01338 MSG("LIPlexMaps",Msg::kInfo)
01339 <<"Mean="<<kMean<<", rms="<<kRms
01340 <<", N="<<numFlashes[j]
01341 <<", Errors: eMean="<<kRms/sqrt(numFlashes[j])
01342 <<" ("<<((kRms/sqrt(numFlashes[j]))/kMean)*100<<"%)"
01343 <<", eRms="<<kRms/sqrt(numFlashes[j])
01344 <<" ("<<(1/sqrt(numFlashes[j]))*100<<"%)"
01345 <<", eGain="
01346 <<"("<<((1/sqrt(numFlashes[j]))*2+
01347 (kRms/sqrt(numFlashes[j]))/kMean)*100<<"%)"
01348 <<" quad="
01349 <<"("<<sqrt((1/numFlashes[j])*2+
01350 pow((kRms/sqrt(numFlashes[j]))/kMean,2))*100<<"%)"
01351 <<endl;
01352 }
01353
01354 Double_t *mean=new Double_t[kNumPoints*kFlashes];
01355 Double_t *rms=new Double_t[kNumPoints*kFlashes];
01356 Double_t *gain=new Double_t[kNumPoints*kFlashes];
01357 Double_t *xAxis=new Double_t[kNumPoints*kFlashes];
01358
01359 Double_t *rmsOfMean=new Double_t[kNumPoints];
01360 Double_t *rmsOfGain=new Double_t[kNumPoints];
01361 Double_t *rmsOfRms=new Double_t[kNumPoints];
01362 Double_t *errorOnMean=new Double_t[kNumPoints];
01363 Double_t *errorOnGain=new Double_t[kNumPoints];
01364 Double_t *errorOnRms=new Double_t[kNumPoints];
01365 Double_t *errorOnMeanN=new Double_t[kNumPoints];
01366 Double_t *errorOnGainN=new Double_t[kNumPoints];
01367 Double_t *errorOnRmsN=new Double_t[kNumPoints];
01368
01369 const Int_t kNumLiRuns=1000;
01370
01371 MSG("LIPlexMaps",Msg::kInfo)
01372 <<endl<<"Calculating errors by MC"<<endl;
01373
01374 for (Int_t j=0;j<kNumPoints;j++){
01375 numFlashes[j]=static_cast<Double_t>((j+1)*kFlashes);
01376 MSG("LIPlexMaps",Msg::kInfo)
01377 <<endl<<"Point "<<j+1<<"/"<<kNumPoints
01378 <<", numFlashes="<<numFlashes[j]<<endl;
01379
01380 stopwatch.Start();
01381
01382
01383 for (Int_t k=0;k<kNumLiRuns;k++){
01384 hADC->Reset();
01385 for (Int_t i=0;i<(j+1)*kFlashes;i++){
01386
01387 hADC->Fill(kAdcsPerPe*this->SampleDist(vBinomial,tRandom));
01388 }
01389 mean[k]=hADC->GetMean();
01390 rms[k]=hADC->GetRMS();
01391 gain[k]=fLookup.CalcGain(mean[k],rms[k],kQE);
01392 xAxis[k]=static_cast<Double_t>(k);
01393 rmsOfMean[j]+=pow(kMean-mean[k],2);
01394 rmsOfGain[j]+=pow(kGain-gain[k],2);
01395 rmsOfRms[j]+=pow(kRms-rms[k],2);
01396 }
01397
01398 stopwatch.Stop();
01399 MSG("LIPlexMaps",Msg::kInfo)
01400 <<"Time elapsed, real="<<stopwatch.RealTime()
01401 <<", cpu="<<stopwatch.CpuTime()
01402 <<endl;
01403
01404
01405 rmsOfMean[j]=sqrt(rmsOfMean[j]/kNumLiRuns);
01406 rmsOfGain[j]=sqrt(rmsOfGain[j]/kNumLiRuns);
01407 rmsOfRms[j]=sqrt(rmsOfRms[j]/kNumLiRuns);
01408
01409
01410
01411
01412 errorOnMean[j]=rmsOfMean[j]/sqrt(1.);
01413 errorOnGain[j]=rmsOfGain[j]/sqrt(1.);
01414 errorOnRms[j]=rmsOfRms[j]/sqrt(1.);
01415
01416
01417 errorOnMeanN[j]=errorOnMean[j]/kMean;
01418 errorOnGainN[j]=errorOnGain[j]/kGain;
01419 errorOnRmsN[j]=errorOnRms[j]/kRms;
01420
01421 MSG("LIPlexMaps",Msg::kInfo)
01422 <<"Errors: eMean="<<errorOnMean[j]
01423 <<" ("<<errorOnMeanN[j]*100<<"%)"
01424 <<", eGain="<<errorOnGain[j]
01425 <<" ("<<errorOnGainN[j]*100<<"%)"
01426 <<", eRms="<<errorOnRms[j]
01427 <<" ("<<errorOnRmsN[j]*100<<"%)"
01428 <<endl;
01429 }
01430
01431
01432 TCanvas *cGain=new TCanvas("cGain","cGain",1,1,1000,800);
01433 cGain->SetFillColor(0);
01434 cGain->Divide(1,2);
01435
01436 TGraph *gGain=new TGraph(kNumLiRuns,xAxis,gain);
01437 gGain->SetTitle("Gain Vs 'run'");
01438 gGain->SetMarkerStyle(3);
01439 gGain->SetMarkerColor(2);
01440 gGain->SetMarkerSize(0.4);
01441 cGain->cd(1);
01442 gGain->Draw("AP");
01443 gGain->GetXaxis()->SetTitle("'run' number");
01444 gGain->GetYaxis()->SetTitle("Gain");
01445 gGain->GetXaxis()->CenterTitle();
01446 gGain->GetYaxis()->CenterTitle();
01447
01448 TGraph *gMean=new TGraph(kNumLiRuns,xAxis,mean);
01449 gMean->SetTitle("Mean Vs 'run'");
01450 gMean->SetMarkerStyle(3);
01451 gMean->SetMarkerColor(2);
01452 gMean->SetMarkerSize(0.4);
01453 cGain->cd(2);
01454 gMean->Draw("AP");
01455 gMean->GetXaxis()->SetTitle("'run' number");
01456 gMean->GetYaxis()->SetTitle("Mean");
01457 gMean->GetXaxis()->CenterTitle();
01458 gMean->GetYaxis()->CenterTitle();
01459
01461
01463
01464 TCanvas *cGainError=new TCanvas("cGainError","cGainError",
01465 1,1,1000,800);
01466 cGainError->SetFillColor(0);
01467 cGainError->Divide(1,2);
01468
01469
01470 TGraph *gGainErrorNormVsFlashes=new TGraph(kNumPoints,
01471 numFlashes,errorOnGainN);
01472 gGainErrorNormVsFlashes->SetTitle
01473 ("Fractional Error on Gain Vs Flashes");
01474 gGainErrorNormVsFlashes->SetMarkerStyle(3);
01475 gGainErrorNormVsFlashes->SetMarkerColor(2);
01476 gGainErrorNormVsFlashes->SetMarkerSize(0.2);
01477 cGainError->cd(1);
01478 gGainErrorNormVsFlashes->Draw("AP");
01479 gGainErrorNormVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01480 gGainErrorNormVsFlashes->GetYaxis()->SetTitle
01481 ("Fractional Error on Gain");
01482 gGainErrorNormVsFlashes->GetXaxis()->CenterTitle();
01483 gGainErrorNormVsFlashes->GetYaxis()->CenterTitle();
01484 gGainErrorNormVsFlashes->SetMinimum(0);
01485
01486
01487 TGraph *gGainErrorVsFlashes=new TGraph(kNumPoints,
01488 numFlashes,errorOnGain);
01489 gGainErrorVsFlashes->SetTitle("Error on Gain Vs Flashes");
01490 gGainErrorVsFlashes->SetMarkerStyle(3);
01491 gGainErrorVsFlashes->SetMarkerColor(2);
01492 gGainErrorVsFlashes->SetMarkerSize(0.2);
01493 cGainError->cd(2);
01494 gGainErrorVsFlashes->Draw("AP");
01495 gGainErrorVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01496 gGainErrorVsFlashes->GetYaxis()->SetTitle("Error on Gain");
01497 gGainErrorVsFlashes->GetXaxis()->CenterTitle();
01498 gGainErrorVsFlashes->GetYaxis()->CenterTitle();
01499
01501
01503
01504 TCanvas *cGainMean=new TCanvas("cGainMean","cGainMean",1,1,1000,800);
01505 cGainMean->SetFillColor(0);
01506 cGainMean->Divide(1,2);
01507
01508
01509 TGraph *gMeanErrorNormVsFlashes=new TGraph(kNumPoints,
01510 numFlashes,errorOnMeanN);
01511 gMeanErrorNormVsFlashes->SetTitle
01512 ("Fractional Error on Mean Vs Flashes");
01513 gMeanErrorNormVsFlashes->SetMarkerStyle(3);
01514 gMeanErrorNormVsFlashes->SetMarkerColor(2);
01515 gMeanErrorNormVsFlashes->SetMarkerSize(0.2);
01516 cGainMean->cd(1);
01517 gMeanErrorNormVsFlashes->Draw("AP");
01518 gMeanErrorNormVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01519 gMeanErrorNormVsFlashes->GetYaxis()->SetTitle
01520 ("Fractional Error on Mean");
01521 gMeanErrorNormVsFlashes->GetXaxis()->CenterTitle();
01522 gMeanErrorNormVsFlashes->GetYaxis()->CenterTitle();
01523 gMeanErrorNormVsFlashes->SetMinimum(0);
01524
01525
01526 TGraph *gMeanErrorVsFlashes=new TGraph(kNumPoints,
01527 numFlashes,errorOnMean);
01528 gMeanErrorVsFlashes->SetTitle("Error on Mean Vs Flashes");
01529 gMeanErrorVsFlashes->SetMarkerStyle(3);
01530 gMeanErrorVsFlashes->SetMarkerColor(2);
01531 gMeanErrorVsFlashes->SetMarkerSize(0.2);
01532 cGainMean->cd(2);
01533 gMeanErrorVsFlashes->Draw("AP");
01534 gMeanErrorVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01535 gMeanErrorVsFlashes->GetYaxis()->SetTitle("Error on Mean");
01536 gMeanErrorVsFlashes->GetXaxis()->CenterTitle();
01537 gMeanErrorVsFlashes->GetYaxis()->CenterTitle();
01538
01540
01542
01543 TCanvas *cRmsErr=new TCanvas("cRmsErr","cRmsErr",1,1,1000,800);
01544 cRmsErr->SetFillColor(0);
01545 cRmsErr->Divide(1,2);
01546
01547
01548 TGraph *gRmsErrorNormVsFlashes=new TGraph(kNumPoints,
01549 numFlashes,errorOnRmsN);
01550 gRmsErrorNormVsFlashes->SetTitle
01551 ("Fractional Error on Rms Vs Flashes");
01552 gRmsErrorNormVsFlashes->SetMarkerStyle(3);
01553 gRmsErrorNormVsFlashes->SetMarkerColor(2);
01554 gRmsErrorNormVsFlashes->SetMarkerSize(0.2);
01555 cRmsErr->cd(1);
01556 gRmsErrorNormVsFlashes->Draw("AP");
01557 gRmsErrorNormVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01558 gRmsErrorNormVsFlashes->GetYaxis()->SetTitle
01559 ("Fractional Error on Rms");
01560 gRmsErrorNormVsFlashes->GetXaxis()->CenterTitle();
01561 gRmsErrorNormVsFlashes->GetYaxis()->CenterTitle();
01562 gRmsErrorNormVsFlashes->SetMinimum(0);
01563
01564
01565 TGraph *gRmsErrorVsFlashes=new TGraph(kNumPoints,
01566 numFlashes,errorOnRms);
01567 gRmsErrorVsFlashes->SetTitle("Error on Rms Vs Flashes");
01568 gRmsErrorVsFlashes->SetMarkerStyle(3);
01569 gRmsErrorVsFlashes->SetMarkerColor(2);
01570 gRmsErrorVsFlashes->SetMarkerSize(0.2);
01571 cRmsErr->cd(2);
01572 gRmsErrorVsFlashes->Draw("AP");
01573 gRmsErrorVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01574 gRmsErrorVsFlashes->GetYaxis()->SetTitle("Error on Rms");
01575 gRmsErrorVsFlashes->GetXaxis()->CenterTitle();
01576 gRmsErrorVsFlashes->GetYaxis()->CenterTitle();
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624 MSG("LIPlexMaps",Msg::kInfo)
01625 <<" ** Finished the PeGen method ** "<<endl;
01626 }
01627
01628
01629
01630 void LIPlexMaps::LIErrors()
01631 {
01632 MSG("LIPlexMaps",Msg::kInfo)
01633 <<" ** Running LIErrors method... **"<<endl;
01634
01635
01636 gStyle->SetPalette(1);
01637
01638 gStyle->SetOptStat(1111111);
01639
01640
01641 const Double_t kQE=0.13;
01642 const Double_t kGain=80;
01643
01644 const Int_t kNumPoints=50;
01645
01646 TGraph *gGainErrorNormVsMean=new TGraph(kNumPoints);
01647 TGraph *gMeanErrorNormVsMean=new TGraph(kNumPoints);
01648 TGraph *gRmsErrorNormVsMean=new TGraph(kNumPoints);
01649
01650 for (Int_t i=0;i<kNumPoints;i++){
01651
01652
01653
01654
01655 Double_t roughMean=200*(i+1);
01656 Double_t roughRms=fLookup.CalcRms(roughMean,kGain,kQE);
01657 Double_t roughNpe=fLookup.CalcNpe(roughMean,roughRms,kQE);
01658
01659
01660 Double_t tempN=-1;
01661 Double_t rem=0;
01662 rem=modf(roughNpe/kQE,&tempN);
01663 if (rem>=0.5) tempN++;
01664
01665
01666
01667 const Int_t kN=static_cast<Int_t>(tempN);
01668 const Double_t kNpe=kN*kQE;
01669 const Double_t kMean=kGain*kNpe;
01670 const Double_t kRms=fLookup.CalcRms(kMean,kGain,kQE);
01671 const Double_t kAdcsPerPe=kMean/kNpe;
01672
01673 MSG("LIPlexMaps",Msg::kInfo)
01674 <<endl<<"The following parameters are used in the MC:"<<endl
01675 <<"kQE="<<kQE<<endl
01676 <<"kN="<<kN<<endl
01677 <<"kMean="<<kMean<<endl
01678 <<"kRms="<<kRms<<endl
01679 <<"kGain="<<kGain<<endl
01680 <<"kNpe="<<kNpe<<endl
01681 <<"kAdcsPerPe="<<kAdcsPerPe<<endl;
01682
01683 Double_t numFlashes=1000;
01684 Double_t errorOnMeanN=-1;
01685 Double_t errorOnGainN=-1;
01686 Double_t errorOnRmsN=-1;
01687
01688
01689
01690
01691
01692 errorOnMeanN=(kRms/sqrt(numFlashes))/kMean;
01693 errorOnRmsN=1/sqrt(numFlashes);
01694 errorOnGainN=sqrt(pow(errorOnRmsN,2)*2+
01695 pow(errorOnMeanN,2));
01696
01697 MSG("LIPlexMaps",Msg::kInfo)
01698 <<"Mean="<<kMean<<", rms="<<kRms
01699 <<", N="<<numFlashes
01700 <<", Errors: eMean="
01701 <<"("<<errorOnMeanN*100<<"%)"
01702 <<", eRms="
01703 <<"("<<errorOnRmsN*100<<"%)"
01704 <<", eGain="<<"("<<errorOnGainN*100<<"%)"
01705 <<endl;
01706
01707 gGainErrorNormVsMean->SetPoint(i,kMean,errorOnGainN);
01708 gMeanErrorNormVsMean->SetPoint(i,kMean,errorOnMeanN);
01709 gRmsErrorNormVsMean->SetPoint(i,kMean,errorOnRmsN);
01710 }
01711
01713
01715
01716 TCanvas *cGainErrorVsMean=new TCanvas("cGainErrorVsMean",
01717 "cGainErrorVsMean",
01718 1,1,1000,800);
01719 cGainErrorVsMean->SetFillColor(0);
01720
01721 gGainErrorNormVsMean->SetTitle("Fractional Error on Gain Vs Mean");
01722 gGainErrorNormVsMean->SetMarkerStyle(3);
01723 gGainErrorNormVsMean->SetMarkerColor(2);
01724 gGainErrorNormVsMean->SetMarkerSize(0.2);
01725 cGainErrorVsMean->cd(1);
01726 gGainErrorNormVsMean->Draw("AP");
01727 gGainErrorNormVsMean->GetXaxis()->SetTitle("Mean");
01728 gGainErrorNormVsMean->GetYaxis()->SetTitle
01729 ("Fractional Error on Gain");
01730 gGainErrorNormVsMean->GetXaxis()->CenterTitle();
01731 gGainErrorNormVsMean->GetYaxis()->CenterTitle();
01732 gGainErrorNormVsMean->SetMinimum(0);
01733
01735
01737
01738 TCanvas *cMeanErrorVsMean=new TCanvas("cMeanErrorVsMean",
01739 "cMeanErrorVsMean",
01740 1,1,1000,800);
01741 cMeanErrorVsMean->SetFillColor(0);
01742
01743 gMeanErrorNormVsMean->SetTitle("Fractional Error on Mean Vs Mean");
01744 gMeanErrorNormVsMean->SetMarkerStyle(3);
01745 gMeanErrorNormVsMean->SetMarkerColor(2);
01746 gMeanErrorNormVsMean->SetMarkerSize(0.2);
01747 cMeanErrorVsMean->cd(1);
01748 gMeanErrorNormVsMean->Draw("AP");
01749 gMeanErrorNormVsMean->GetXaxis()->SetTitle("Mean");
01750 gMeanErrorNormVsMean->GetYaxis()->SetTitle
01751 ("Fractional Error on Mean");
01752 gMeanErrorNormVsMean->GetXaxis()->CenterTitle();
01753 gMeanErrorNormVsMean->GetYaxis()->CenterTitle();
01754 gMeanErrorNormVsMean->SetMinimum(0);
01755
01757
01759
01760 TCanvas *cRmsErrVsMean=new TCanvas("cRmsErrVsMean","cRmsErrVsMean",
01761 1,1,1000,800);
01762 cRmsErrVsMean->SetFillColor(0);
01763
01764 gRmsErrorNormVsMean->SetTitle
01765 ("Fractional Error on Rms Vs Mean");
01766 gRmsErrorNormVsMean->SetMarkerStyle(3);
01767 gRmsErrorNormVsMean->SetMarkerColor(2);
01768 gRmsErrorNormVsMean->SetMarkerSize(0.2);
01769 cRmsErrVsMean->cd(1);
01770 gRmsErrorNormVsMean->Draw("AP");
01771 gRmsErrorNormVsMean->GetXaxis()->SetTitle("Mean");
01772 gRmsErrorNormVsMean->GetYaxis()->SetTitle
01773 ("Fractional Error on Rms");
01774 gRmsErrorNormVsMean->GetXaxis()->CenterTitle();
01775 gRmsErrorNormVsMean->GetYaxis()->CenterTitle();
01776 gRmsErrorNormVsMean->SetMinimum(0);
01777
01778 MSG("LIPlexMaps",Msg::kInfo)
01779 <<" ** Finished the LIErrors method ** "<<endl;
01780 }
01781
01782
01783
01784 void LIPlexMaps::PlotPlexPinMap()
01785 {
01786 MSG("LIAnalysis",Msg::kInfo)
01787 <<"Running PlotPlexPinMap method..."<<endl;
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529 MSG("LIAnalysis",Msg::kInfo)
02530 <<"PlotPlexPinMap method finished"<<endl;
02531 }
02532
02533
02534
02535 void LIPlexMaps::PrintDbPinDiodeInfo()
02536 {
02537 VldTimeStamp timeStamp;
02538
02539
02540 VldContext vldc(Detector::kFar,SimFlag::kData,timeStamp);
02541
02542 DbiResultPtr<PlexRawChannelToPinDiode> rc2pdResPtr(vldc);
02543
02544 cout<<"Num of PlexRawChannelToPinDiode rows="
02545 <<rc2pdResPtr.GetNumRows()<<endl;
02546
02547 for (UInt_t irow = 0; irow < rc2pdResPtr.GetNumRows(); ++irow) {
02548
02549 const PlexRawChannelToPinDiode* rc2pd = rc2pdResPtr.GetRow(irow);
02550
02551 RawChannelId rcid = rc2pd->GetRawChannelId();
02552 PlexPinDiodeId pinid = rc2pd->GetPlexPinDiodeId();
02553
02554 cout<<"row="<<irow<<", rcid="<<this->GetElecString(rcid)
02555 <<", pinid="<<pinid<<", g="<<pinid.GetGain()
02556 <<", inbox="<<pinid.GetInBox()<<endl;
02557 }
02558
02559
02560 cout<<"gain==0"<<endl;
02561 for (UInt_t irow = 0; irow < rc2pdResPtr.GetNumRows(); ++irow) {
02562
02563 const PlexRawChannelToPinDiode* rc2pd = rc2pdResPtr.GetRow(irow);
02564
02565 RawChannelId rcid = rc2pd->GetRawChannelId();
02566 PlexPinDiodeId pinid = rc2pd->GetPlexPinDiodeId();
02567
02568 if (pinid.GetGain()==0){
02569 cout<<"row="<<irow<<", rcid="<<this->GetElecString(rcid)
02570 <<", pinid="<<pinid<<", g="<<pinid.GetGain()
02571
02572 <<endl;
02573 }
02574 }
02575
02576
02577 cout<<"gain==1"<<endl;
02578 for (UInt_t irow = 0; irow < rc2pdResPtr.GetNumRows(); ++irow) {
02579
02580 const PlexRawChannelToPinDiode* rc2pd = rc2pdResPtr.GetRow(irow);
02581
02582 RawChannelId rcid = rc2pd->GetRawChannelId();
02583 PlexPinDiodeId pinid = rc2pd->GetPlexPinDiodeId();
02584
02585 if (pinid.GetGain()==1){
02586 cout<<"row="<<irow<<", rcid="<<this->GetElecString(rcid)
02587 <<", pinid="<<pinid<<", g="<<pinid.GetGain()
02588
02589 <<endl;
02590 }
02591 }
02592
02593 }
02594
02595
02596
02597 void LIPlexMaps::PrintPlexPinDiodeInfo(Int_t detectorType)
02598 {
02599 MSG("LIPlexMaps",Msg::kInfo)
02600 <<"Running PrintPlexPinDiodeInfo method..."<<endl;
02601
02602
02603
02604 VldTimeStamp timeStamp;
02605
02606
02607
02608
02609 VldContext* validityContext;
02610 if (detectorType==Detector::kFar){
02611 validityContext=new VldContext(Detector::kFar,SimFlag::kData,
02612 timeStamp);
02613 }
02614 else if (detectorType==Detector::kCalDet){
02615 validityContext=new VldContext(Detector::kCalDet,SimFlag::kData,
02616 timeStamp);
02617 }
02618 else if (detectorType==Detector::kNear){
02619 validityContext=new VldContext(Detector::kNear,SimFlag::kData,
02620 timeStamp);
02621 }
02622 else{
02623 MSG("LIPlexMaps",Msg::kError)
02624 <<"Detector type not known = "<<detectorType
02625 <<endl<<"Program will exit here!"<<endl;
02626 exit(1);
02627 }
02628
02629 MSG("LIPlexMaps",Msg::kInfo)
02630 <<"Using validity context: "<<validityContext->AsString()<<endl;
02631
02632
02633 PlexHandle *plexHandle=new PlexHandle(*validityContext);
02634
02635
02636 LedIdList leds(*validityContext);
02637 LedIdList::iterator ledId=leds.begin();
02638
02639
02640 MSG("LIPlexMaps",Msg::kInfo)
02641 <<endl
02642 <<"The pin diode information in the plex is as follows"<<endl
02643 <<"The electronics information is in descending hierarchial order"
02644 <<endl
02645 <<"(x:y) is pulser box x and led y"<<endl
02646 <<"e.g. (crate,varc,vmm,vfb,VA chip,VA channel)"<<endl<<endl;
02647
02648
02649 while (ledId!=leds.end()){
02650
02651 if (!(*ledId).IsValid()){
02652 MSG("LIPlexMaps",Msg::kWarning)
02653 <<"LedId not valid = "<<ledId->AsString()<<endl;
02654 }
02655
02656
02657 pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
02658 GetPinDiodeIds(*ledId);
02659
02660
02661 MSG("LIPlexMaps",Msg::kVerbose)
02662 <<"first pin gain="<<plexPins.first.GetGain()
02663 <<", second pin gain="<<plexPins.second.GetGain()<<endl;
02664
02665
02666 pair<Int_t,Int_t> pin1Planes=fLookup.GetPinDiodePlanes
02667 (plexPins.first,plexHandle);
02668 pair<Int_t,Int_t> pin2Planes=fLookup.GetPinDiodePlanes
02669 (plexPins.second,plexHandle);
02670
02671
02672 pair<RawChannelId,RawChannelId> rawChanIds;
02673 rawChanIds.first=plexHandle->GetRawChannelId(plexPins.first);
02674 rawChanIds.second=plexHandle->GetRawChannelId(plexPins.second);
02675
02676
02677
02678 string sPlane1=Form("%d",pin1Planes.first);
02679 string sPlane2=Form("%d",pin1Planes.second);
02680
02681 string sPin1Planes=" Planes="+sPlane1+"&"+sPlane2;
02682 if (pin1Planes.second==-1){
02683 sPin1Planes=" Plane="+sPlane1;
02684 }
02685
02686 sPlane1=Form("%d",pin2Planes.first);
02687 sPlane2=Form("%d",pin2Planes.second);
02688 string sPin2Planes=" Planes="+sPlane1+"&"+sPlane2;
02689 if (pin2Planes.second==-1){
02690 sPin2Planes=" Plane="+sPlane1;
02691 }
02692
02693 MSG("LIPlexMaps",Msg::kInfo)
02694 <<endl
02695 <<"("<<ledId->GetPulserBox()<<":"<<ledId->GetLedInBox()<<")"
02696 <<" Pin1="<<this->GetElecString(rawChanIds.first)
02697 <<"="<<rawChanIds.first.GetChAdd()
02698 <<" MUX BOX: E/W="<<plexPins.first.GetEastWest()
02699 <<", rLevel="<<plexPins.first.GetRackLevel()
02700 <<", rBay="<<plexPins.first.GetRackBay()
02701 <<", inRack="<<plexPins.first.GetInRack()
02702 <<sPin1Planes
02703 <<endl
02704
02705 <<"("<<ledId->GetPulserBox()<<":"<<ledId->GetLedInBox()<<")"
02706 <<" Pin2="<<this->GetElecString(rawChanIds.second)
02707 <<"="<<rawChanIds.second.GetChAdd()
02708 <<" MUX BOX: E/W="<<plexPins.second.GetEastWest()
02709 <<", rLevel="<<plexPins.second.GetRackLevel()
02710 <<", rBay="<<plexPins.second.GetRackBay()
02711 <<", inRack="<<plexPins.second.GetInRack()
02712 <<sPin2Planes
02713 <<endl;
02714
02715 ledId++;
02716 }
02717
02718 MSG("LIPlexMaps",Msg::kInfo)
02719 <<endl<<" ** Finished the PrintPlexPinDiodeInfo method ** "
02720 <<endl;
02721 }
02722
02723
02724
02725 string LIPlexMaps::GetElecString(RawChannelId rChId)
02726 {
02727 MSG("LISummarySorter",Msg::kVerbose)
02728 <<"Running GetElecString method..."<<endl;
02729
02730 string elecString="";
02731 string sCrate=Form("%d",rChId.GetCrate());
02732 string sElecType=ElecType::AsString(rChId.GetElecType());
02733
02734 if (rChId.GetElecType()==ElecType::kVA){
02735 string sVarc=Form("%d",rChId.GetVarcId());
02736 string sVmm=Form("%d",rChId.GetVmm());
02737 string sVfb=Form("%d",rChId.GetVaAdcSel());
02738 string sChip=Form("%d",rChId.GetVaChip());
02739 string sChannel=Form("%d",rChId.GetVaChannel());
02740
02741 elecString=sElecType+
02742 "("+sCrate+","+sVarc+","+sVmm+","+sVfb+","+sChip+","+sChannel+")";
02743 }
02744 else if (rChId.GetElecType()==ElecType::kQIE){
02745 string sGeoAdd=Form("%d",rChId.GetGeographicAddress());
02746 string sMaster=Form("%d",rChId.GetMasterChannel());
02747 string sMinder=Form("%d",rChId.GetMinderChannel());
02748
02749 elecString=sElecType+
02750 "("+sCrate+","+sGeoAdd+","+sMaster+","+sMinder+")";
02751 }
02752 return elecString;
02753 }
02754
02755
02756
02757 void LIPlexMaps::PlotPlexStripMap(Int_t detectorType)
02758 {
02759 MSG("LIPlexMaps",Msg::kInfo)
02760 <<"Running PlotPlexStripMap method..."<<endl;
02761
02762 Int_t planeMax=-1;
02763 Int_t planeMin=-1;
02764
02765 planeMin=FIRSTSCINTPLANE-2;
02766 planeMax=LASTSCINTPLANE+5;
02767
02768 const Int_t firstStripBin=FIRSTSTRIP-8;
02769 const Int_t lastStripBin=LASTSTRIP+9;
02770 const Int_t bins=lastStripBin-firstStripBin;
02771
02772
02773
02774
02775 VldTimeStamp timeStamp(2001,7,1,1,1,1,1,0,0);
02776
02777
02778 VldContext* validityContext;
02779
02780 if (detectorType==Detector::kFar){
02781 validityContext=new VldContext(Detector::kFar,
02782 SimFlag::kData,timeStamp);
02783 }
02784 else if (detectorType==Detector::kCalDet){
02785 validityContext=new VldContext(Detector::kCalDet,
02786 SimFlag::kData,timeStamp);
02787 }
02788 else if (detectorType==Detector::kNear){
02789 validityContext=new VldContext(Detector::kNear,
02790 SimFlag::kData,timeStamp);
02791 }
02792 else{
02793 MSG("LIPlexMaps",Msg::kError)
02794 <<"Detector type not known = "<<detectorType
02795 <<endl<<"Program will exit here!"<<endl;
02796 exit(1);
02797 }
02798
02799 MSG("LIPlexMaps",Msg::kInfo)
02800 <<"Using validity context: "<<validityContext->AsString()<<endl;
02801
02802 PlexHandle *plexhandle=new PlexHandle(*validityContext);
02803
02804 TH2F *hStripVsPlaneLed=new TH2F("hStripVsPlaneLed",
02805 "Led (StripEnd=kNeg=kEast)",
02806 planeMax-planeMin,
02807 planeMin,planeMax,
02808 bins,firstStripBin,lastStripBin);
02809 hStripVsPlaneLed->GetXaxis()->SetTitle("Plane");
02810 hStripVsPlaneLed->GetXaxis()->CenterTitle();
02811 hStripVsPlaneLed->GetYaxis()->SetTitle("Strip");
02812 hStripVsPlaneLed->GetYaxis()->CenterTitle();
02813 hStripVsPlaneLed->SetFillColor(0);
02814
02815
02816 TH2F *hStripVsPlanePix=new TH2F("hStripVsPlanePix",
02817 "Pixel (StripEnd=kNeg=kEast)",
02818 planeMax-planeMin,planeMin,planeMax,
02819 bins,firstStripBin,lastStripBin);
02820 hStripVsPlanePix->GetXaxis()->SetTitle("Plane");
02821 hStripVsPlanePix->GetXaxis()->CenterTitle();
02822 hStripVsPlanePix->GetYaxis()->SetTitle("Strip");
02823 hStripVsPlanePix->GetYaxis()->CenterTitle();
02824 hStripVsPlanePix->SetFillColor(0);
02825 hStripVsPlanePix->SetMinimum(-2);
02826
02827
02828 TH2F *hStripVsPlaneCrate=new TH2F("hStripVsPlaneCrate",
02829 "Crate (StripEnd=kNeg=kEast)",
02830 planeMax-planeMin,planeMin,
02831 planeMax,
02832 bins,firstStripBin,lastStripBin);
02833 hStripVsPlaneCrate->GetXaxis()->SetTitle("Plane");
02834 hStripVsPlaneCrate->GetXaxis()->CenterTitle();
02835 hStripVsPlaneCrate->GetYaxis()->SetTitle("Strip");
02836 hStripVsPlaneCrate->GetYaxis()->CenterTitle();
02837 hStripVsPlaneCrate->SetFillColor(0);
02838 hStripVsPlaneCrate->SetMinimum(-2);
02839
02840
02841 TH2F *hStripVsPlaneVarc=new TH2F("hStripVsPlaneVarc",
02842 "Varc (StripEnd=kNeg=kEast)",
02843 planeMax-planeMin,planeMin,planeMax,
02844 bins,firstStripBin,lastStripBin);
02845 hStripVsPlaneVarc->GetXaxis()->SetTitle("Plane");
02846 hStripVsPlaneVarc->GetXaxis()->CenterTitle();
02847 hStripVsPlaneVarc->GetYaxis()->SetTitle("Strip");
02848 hStripVsPlaneVarc->GetYaxis()->CenterTitle();
02849 hStripVsPlaneVarc->SetFillColor(0);
02850 hStripVsPlaneVarc->SetMinimum(-2);
02851
02852
02853 TH2F *hStripVsPlaneVmm=new TH2F("hStripVsPlaneVmm",
02854 "Vmm (StripEnd=kNeg=kEast)",
02855 planeMax-planeMin,planeMin,planeMax,
02856 bins,firstStripBin,lastStripBin);
02857 hStripVsPlaneVmm->GetXaxis()->SetTitle("Plane");
02858 hStripVsPlaneVmm->GetXaxis()->CenterTitle();
02859 hStripVsPlaneVmm->GetYaxis()->SetTitle("Strip");
02860 hStripVsPlaneVmm->GetYaxis()->CenterTitle();
02861 hStripVsPlaneVmm->SetFillColor(0);
02862 hStripVsPlaneVmm->SetMinimum(-2);
02863
02864
02865 TH2F *hStripVsPlaneVfb=new TH2F("hStripVsPlaneVfb",
02866 "Vfb (StripEnd=kNeg=kEast)",
02867 planeMax-planeMin,planeMin,planeMax,
02868 bins,firstStripBin,lastStripBin);
02869 hStripVsPlaneVfb->GetXaxis()->SetTitle("Plane");
02870 hStripVsPlaneVfb->GetXaxis()->CenterTitle();
02871 hStripVsPlaneVfb->GetYaxis()->SetTitle("Strip");
02872 hStripVsPlaneVfb->GetYaxis()->CenterTitle();
02873 hStripVsPlaneVfb->SetFillColor(0);
02874 hStripVsPlaneVfb->SetMinimum(-2);
02875
02876
02877 TH2F *hStripVsPlaneVaChip=new TH2F("hStripVsPlaneVaChip",
02878 "VA Chip (StripEnd=kNeg=kEast)",
02879 planeMax-planeMin,planeMin,planeMax,
02880 bins,firstStripBin,lastStripBin);
02881 hStripVsPlaneVaChip->GetXaxis()->SetTitle("Plane");
02882 hStripVsPlaneVaChip->GetXaxis()->CenterTitle();
02883 hStripVsPlaneVaChip->GetYaxis()->SetTitle("Strip");
02884 hStripVsPlaneVaChip->GetYaxis()->CenterTitle();
02885 hStripVsPlaneVaChip->SetFillColor(0);
02886 hStripVsPlaneVaChip->SetMinimum(-2);
02887
02888
02889 TH2F *hStripVsPlaneCh=new TH2F("hStripVsPlaneCh",
02890 "VA Channel (StripEnd=kNeg=kEast)",
02891 planeMax-planeMin,planeMin,planeMax,
02892 bins,firstStripBin,lastStripBin);
02893 hStripVsPlaneCh->GetXaxis()->SetTitle("Plane");
02894 hStripVsPlaneCh->GetXaxis()->CenterTitle();
02895 hStripVsPlaneCh->GetYaxis()->SetTitle("Strip");
02896 hStripVsPlaneCh->GetYaxis()->CenterTitle();
02897 hStripVsPlaneCh->SetFillColor(0);
02898 hStripVsPlaneCh->SetMinimum(-2);
02899
02900
02901 TH2F *hStripVsPlaneGeoAdd=new TH2F("hStripVsPlaneGeoAdd",
02902 "Geographic Address (StripEnd=kNeg=kEast)",
02903 planeMax-planeMin,planeMin,
02904 planeMax,
02905 bins,firstStripBin,lastStripBin);
02906 hStripVsPlaneGeoAdd->GetXaxis()->SetTitle("Plane");
02907 hStripVsPlaneGeoAdd->GetXaxis()->CenterTitle();
02908 hStripVsPlaneGeoAdd->GetYaxis()->SetTitle("Strip");
02909 hStripVsPlaneGeoAdd->GetYaxis()->CenterTitle();
02910 hStripVsPlaneGeoAdd->SetFillColor(0);
02911 hStripVsPlaneGeoAdd->SetMinimum(-2);
02912
02913
02914 TH2F *hStripVsPlaneMasterCh=new TH2F("hStripVsPlaneMasterCh",
02915 "Master Channel (StripEnd=kNeg=kEast)",
02916 planeMax-planeMin,
02917 planeMin,planeMax,
02918 bins,
02919 firstStripBin,lastStripBin);
02920 hStripVsPlaneMasterCh->GetXaxis()->SetTitle("Plane");
02921 hStripVsPlaneMasterCh->GetXaxis()->CenterTitle();
02922 hStripVsPlaneMasterCh->GetYaxis()->SetTitle("Strip");
02923 hStripVsPlaneMasterCh->GetYaxis()->CenterTitle();
02924 hStripVsPlaneMasterCh->SetFillColor(0);
02925 hStripVsPlaneMasterCh->SetMinimum(-2);
02926
02927
02928 TH2F *hStripVsPlaneMinderCh=new TH2F("hStripVsPlaneMinderCh",
02929 "Minder Channel (StripEnd=kNeg=kEast)",
02930 planeMax-planeMin,
02931 planeMin,planeMax,
02932 bins,
02933 firstStripBin,lastStripBin);
02934 hStripVsPlaneMinderCh->GetXaxis()->SetTitle("Plane");
02935 hStripVsPlaneMinderCh->GetXaxis()->CenterTitle();
02936 hStripVsPlaneMinderCh->GetYaxis()->SetTitle("Strip");
02937 hStripVsPlaneMinderCh->GetYaxis()->CenterTitle();
02938 hStripVsPlaneMinderCh->SetFillColor(0);
02939 hStripVsPlaneMinderCh->SetMinimum(-2);
02940
02941
02942 TH2F *hStripVsPlaneSpot=new TH2F("hStripVsPlaneSpot",
02943 "Pixel Spot (StripEnd=kNeg=kEast)",
02944 planeMax-planeMin,planeMin,planeMax,
02945 bins,firstStripBin,lastStripBin);
02946 hStripVsPlaneSpot->GetXaxis()->SetTitle("Plane");
02947 hStripVsPlaneSpot->GetXaxis()->CenterTitle();
02948 hStripVsPlaneSpot->GetYaxis()->SetTitle("Strip");
02949 hStripVsPlaneSpot->GetYaxis()->CenterTitle();
02950 hStripVsPlaneSpot->SetFillColor(0);
02951 hStripVsPlaneSpot->SetMinimum(-2);
02952
02953
02954 TH2F *hStripVsPlaneEnt=new TH2F("hStripVsPlaneEnt",
02955 "Number Entries (StripEnd=kNeg=kEast)",
02956 planeMax-planeMin,planeMin,planeMax,
02957 bins,firstStripBin,lastStripBin);
02958 hStripVsPlaneEnt->GetXaxis()->SetTitle("Plane");
02959 hStripVsPlaneEnt->GetXaxis()->CenterTitle();
02960 hStripVsPlaneEnt->GetYaxis()->SetTitle("Strip");
02961 hStripVsPlaneEnt->GetYaxis()->CenterTitle();
02962 hStripVsPlaneEnt->SetFillColor(0);
02963 hStripVsPlaneEnt->SetMinimum(-2);
02964
02965
02967
02969 TH2F *hStripVsPlane2Led=new TH2F("hStripVsPlane2Led",
02970 "Led (StripEnd=kPos=kWest)",
02971 planeMax-planeMin,
02972 planeMin,planeMax,
02973 bins,firstStripBin,lastStripBin);
02974 hStripVsPlane2Led->GetXaxis()->SetTitle("Plane");
02975 hStripVsPlane2Led->GetXaxis()->CenterTitle();
02976 hStripVsPlane2Led->GetYaxis()->SetTitle("Strip");
02977 hStripVsPlane2Led->GetYaxis()->CenterTitle();
02978 hStripVsPlane2Led->SetFillColor(0);
02979
02980
02981 TH2F *hStripVsPlane2Pix=new TH2F("hStripVsPlane2Pix",
02982 "Pixel (StripEnd=kPos=kWest)",
02983 planeMax-planeMin,planeMin,planeMax,
02984 bins,firstStripBin,lastStripBin);
02985 hStripVsPlane2Pix->GetXaxis()->SetTitle("Plane");
02986 hStripVsPlane2Pix->GetXaxis()->CenterTitle();
02987 hStripVsPlane2Pix->GetYaxis()->SetTitle("Strip");
02988 hStripVsPlane2Pix->GetYaxis()->CenterTitle();
02989 hStripVsPlane2Pix->SetFillColor(0);
02990 hStripVsPlane2Pix->SetMinimum(-2);
02991
02992
02993 TH2F *hStripVsPlane2Crate=new TH2F("hStripVsPlane2Crate",
02994 "Crate (StripEnd=kPos=kWest)",
02995 planeMax-planeMin,planeMin,planeMax,
02996 bins,firstStripBin,lastStripBin);
02997 hStripVsPlane2Crate->GetXaxis()->SetTitle("Plane");
02998 hStripVsPlane2Crate->GetXaxis()->CenterTitle();
02999 hStripVsPlane2Crate->GetYaxis()->SetTitle("Strip");
03000 hStripVsPlane2Crate->GetYaxis()->CenterTitle();
03001 hStripVsPlane2Crate->SetFillColor(0);
03002 hStripVsPlane2Crate->SetMinimum(-2);
03003
03004
03005 TH2F *hStripVsPlane2Varc=new TH2F("hStripVsPlane2Varc",
03006 "Varc (StripEnd=kPos=kWest)",
03007 planeMax-planeMin,planeMin,planeMax,
03008 bins,firstStripBin,lastStripBin);
03009 hStripVsPlane2Varc->GetXaxis()->SetTitle("Plane");
03010 hStripVsPlane2Varc->GetXaxis()->CenterTitle();
03011 hStripVsPlane2Varc->GetYaxis()->SetTitle("Strip");
03012 hStripVsPlane2Varc->GetYaxis()->CenterTitle();
03013 hStripVsPlane2Varc->SetFillColor(0);
03014 hStripVsPlane2Varc->SetMinimum(-2);
03015
03016
03017 TH2F *hStripVsPlane2Vmm=new TH2F("hStripVsPlane2Vmm",
03018 "Vmm (StripEnd=kPos=kWest)",
03019 planeMax-planeMin,planeMin,planeMax,
03020 bins,firstStripBin,lastStripBin);
03021 hStripVsPlane2Vmm->GetXaxis()->SetTitle("Plane");
03022 hStripVsPlane2Vmm->GetXaxis()->CenterTitle();
03023 hStripVsPlane2Vmm->GetYaxis()->SetTitle("Strip");
03024 hStripVsPlane2Vmm->GetYaxis()->CenterTitle();
03025 hStripVsPlane2Vmm->SetFillColor(0);
03026 hStripVsPlane2Vmm->SetMinimum(-2);
03027
03028
03029 TH2F *hStripVsPlane2Vfb=new TH2F("hStripVsPlane2Vfb",
03030 "Vfb (StripEnd=kPos=kWest)",
03031 planeMax-planeMin,planeMin,planeMax,
03032 bins,firstStripBin,lastStripBin);
03033 hStripVsPlane2Vfb->GetXaxis()->SetTitle("Plane");
03034 hStripVsPlane2Vfb->GetXaxis()->CenterTitle();
03035 hStripVsPlane2Vfb->GetYaxis()->SetTitle("Strip");
03036 hStripVsPlane2Vfb->GetYaxis()->CenterTitle();
03037 hStripVsPlane2Vfb->SetFillColor(0);
03038 hStripVsPlane2Vfb->SetMinimum(-2);
03039
03040
03041 TH2F *hStripVsPlane2VaChip=new TH2F("hStripVsPlane2VaChip",
03042 "Va Chip(StripEnd=kPos=kWest)",
03043 planeMax-planeMin,planeMin,planeMax,
03044 bins,firstStripBin,lastStripBin);
03045 hStripVsPlane2VaChip->GetXaxis()->SetTitle("Plane");
03046 hStripVsPlane2VaChip->GetXaxis()->CenterTitle();
03047 hStripVsPlane2VaChip->GetYaxis()->SetTitle("Strip");
03048 hStripVsPlane2VaChip->GetYaxis()->CenterTitle();
03049 hStripVsPlane2VaChip->SetFillColor(0);
03050 hStripVsPlane2VaChip->SetMinimum(-2);
03051
03052
03053 TH2F *hStripVsPlane2Ch=new TH2F("hStripVsPlane2Ch",
03054 "VA Channel (StripEnd=kPos=kWest)",
03055 planeMax-planeMin,planeMin,planeMax,
03056 bins,firstStripBin,lastStripBin);
03057 hStripVsPlane2Ch->GetXaxis()->SetTitle("Plane");
03058 hStripVsPlane2Ch->GetXaxis()->CenterTitle();
03059 hStripVsPlane2Ch->GetYaxis()->SetTitle("Strip");
03060 hStripVsPlane2Ch->GetYaxis()->CenterTitle();
03061 hStripVsPlane2Ch->SetFillColor(0);
03062 hStripVsPlane2Ch->SetMinimum(-2);
03063
03064
03065 TH2F *hStripVsPlane2GeoAdd=new TH2F("hStripVsPlane2GeoAdd",
03066 "Geographic Address (StripEnd=kPos=kWest)",
03067 planeMax-planeMin,
03068 planeMin,planeMax,
03069 bins,firstStripBin,lastStripBin);
03070 hStripVsPlane2GeoAdd->GetXaxis()->SetTitle("Plane");
03071 hStripVsPlane2GeoAdd->GetXaxis()->CenterTitle();
03072 hStripVsPlane2GeoAdd->GetYaxis()->SetTitle("Strip");
03073 hStripVsPlane2GeoAdd->GetYaxis()->CenterTitle();
03074 hStripVsPlane2GeoAdd->SetFillColor(0);
03075 hStripVsPlane2GeoAdd->SetMinimum(-2);
03076
03077
03078 TH2F *hStripVsPlane2MasterCh=new TH2F("hStripVsPlane2MasterCh",
03079 "Master Channel (StripEnd=kPos=kWest)",
03080 planeMax-planeMin,
03081 planeMin,planeMax,
03082 bins,
03083 firstStripBin,lastStripBin);
03084 hStripVsPlane2MasterCh->GetXaxis()->SetTitle("Plane");
03085 hStripVsPlane2MasterCh->GetXaxis()->CenterTitle();
03086 hStripVsPlane2MasterCh->GetYaxis()->SetTitle("Strip");
03087 hStripVsPlane2MasterCh->GetYaxis()->CenterTitle();
03088 hStripVsPlane2MasterCh->SetFillColor(0);
03089 hStripVsPlane2MasterCh->SetMinimum(-2);
03090
03091
03092 TH2F *hStripVsPlane2MinderCh=new TH2F("hStripVsPlane2MinderCh",
03093 "Minder Channel (StripEnd=kPos=kWest)",
03094 planeMax-planeMin,planeMin,
03095 planeMax,
03096 bins,firstStripBin,
03097 lastStripBin);
03098 hStripVsPlane2MinderCh->GetXaxis()->SetTitle("Plane");
03099 hStripVsPlane2MinderCh->GetXaxis()->CenterTitle();
03100 hStripVsPlane2MinderCh->GetYaxis()->SetTitle("Strip");
03101 hStripVsPlane2MinderCh->GetYaxis()->CenterTitle();
03102 hStripVsPlane2MinderCh->SetFillColor(0);
03103 hStripVsPlane2MinderCh->SetMinimum(-2);
03104
03105
03106 TH2F *hStripVsPlane2Spot=new TH2F("hStripVsPlane2Spot",
03107 "Pixel Spot (StripEnd=kPos=kWest)",
03108 planeMax-planeMin,planeMin,planeMax,
03109 bins,firstStripBin,lastStripBin);
03110 hStripVsPlane2Spot->GetXaxis()->SetTitle("Plane");
03111 hStripVsPlane2Spot->GetXaxis()->CenterTitle();
03112 hStripVsPlane2Spot->GetYaxis()->SetTitle("Strip");
03113 hStripVsPlane2Spot->GetYaxis()->CenterTitle();
03114 hStripVsPlane2Spot->SetFillColor(0);
03115 hStripVsPlane2Spot->SetMinimum(-2);
03116
03117
03118 TH2F *hStripVsPlane2Ent=new TH2F("hStripVsPlane2Ent",
03119 "Number Entries (StripEnd=kPos=kWest)",
03120 planeMax-planeMin,planeMin,planeMax,
03121 bins,firstStripBin,lastStripBin);
03122 hStripVsPlane2Ent->GetXaxis()->SetTitle("Plane");
03123 hStripVsPlane2Ent->GetXaxis()->CenterTitle();
03124 hStripVsPlane2Ent->GetYaxis()->SetTitle("Strip");
03125 hStripVsPlane2Ent->GetYaxis()->CenterTitle();
03126 hStripVsPlane2Ent->SetFillColor(0);
03127 hStripVsPlane2Ent->SetMinimum(-2);
03128
03129
03130
03131 PlexPlaneId* planeId;
03132
03136
03137 for (Int_t pl=planeMin;pl<planeMax;pl++){
03138
03139
03140 if (detectorType==Detector::kFar){
03141 planeId=new PlexPlaneId(Detector::kFar,pl);
03142 }
03143 else if (detectorType==Detector::kCalDet){
03144 planeId=new PlexPlaneId(Detector::kCalDet,pl);
03145 }
03146 else{
03147 planeId=new PlexPlaneId(Detector::kNear,pl);
03148 }
03149
03150 MSG("LIPlexMaps",Msg::kInfo)
03151 <<"pl="<<pl<<", gPl="<<planeId->GetPlane()
03152 <<", view="<<planeId->GetPlaneView()
03153 <<", valid="<<planeId->IsValid()
03154 <<endl;
03155
03156 for (Int_t st=-1;st<NUMSTRIPS+2;st++){
03157 for (Int_t se=0;se<NUMSIDES;se++){
03158
03159
03160 StripEnd::EStripEnd stripEnd = StripEnd::kUnknown;
03161
03162
03163 if (se==0) stripEnd=StripEnd::kEast;
03164 else if (se==1) stripEnd=StripEnd::kWest;
03165
03166
03167 PlexStripEndId stripEndId(*planeId,st,stripEnd);
03168
03169
03170 PlexLedId ledId=plexhandle->GetLedId(stripEndId);
03171 PlexPixelSpotId pixelId=plexhandle->GetPixelSpotId(stripEndId);
03172
03173 Int_t crate=plexhandle->GetRawChannelId(stripEndId).
03174 GetCrate();
03175 Int_t varc=plexhandle->GetRawChannelId(stripEndId).GetVarcId();
03176 Int_t vmm=plexhandle->GetRawChannelId(stripEndId).GetVmm();
03177 Int_t vfb=plexhandle->GetRawChannelId(stripEndId).GetVaAdcSel();
03178 Int_t vaChip=plexhandle->GetRawChannelId(stripEndId).GetVaChip();
03179 Int_t ch=plexhandle->GetRawChannelId(stripEndId).GetVaChannel();
03180
03181 Int_t masterCh=plexhandle->GetRawChannelId(stripEndId).
03182 GetMasterChannel();
03183 Int_t minderCh=plexhandle->GetRawChannelId(stripEndId).
03184 GetMinderChannel();
03185 Int_t geoAdd=plexhandle->GetRawChannelId(stripEndId).
03186 GetGeographicAddress();
03187
03188 if (geoAdd>60000) geoAdd=-1;
03189 if (masterCh>60000) masterCh=-1;
03190 if (minderCh>60000) minderCh=-1;
03191
03192 if (varc>60000) varc=-1;
03193 if (vmm>60000) vmm=-1;
03194 if (vfb>60000) vfb=-1;
03195 if (vaChip>60000) vaChip=-1;
03196 if (ch>60000) ch=-1;
03197
03198
03199 Int_t led=static_cast<Int_t>(ledId.GetLedInBox());
03200 Int_t pix=static_cast<Int_t>(pixelId.GetPixel());
03201 Int_t spot=pixelId.GetSpot();
03202
03203 MSG("LIPlexMaps",Msg::kVerbose)
03204 <<"st="<<st<<", gSt="<<stripEndId.GetStrip()
03205 <<", end="<<stripEndId.GetEnd()
03206 <<", val="<<stripEndId.IsValid()
03207 <<", gled="<<led
03208 <<", gpB="<<ledId.GetPulserBox()
03209 <<", val="<<ledId.IsValid()
03210 <<", pixel="<<pix
03211 <<", val="<<pixelId.IsValid()
03212 <<endl;
03213
03214 if (se==0){
03215
03216 hStripVsPlanePix->Fill(pl,st,pix);
03217 hStripVsPlaneSpot->Fill(pl,st,spot);
03218 hStripVsPlaneCrate->Fill(pl,st,crate);
03219 hStripVsPlaneVarc->Fill(pl,st,varc);
03220 hStripVsPlaneVmm->Fill(pl,st,vmm);
03221 hStripVsPlaneVfb->Fill(pl,st,vfb);
03222 hStripVsPlaneVaChip->Fill(pl,st,vaChip);
03223 hStripVsPlaneCh->Fill(pl,st,ch);
03224 hStripVsPlaneGeoAdd->Fill(pl,st,geoAdd);
03225 hStripVsPlaneMasterCh->Fill(pl,st,masterCh);
03226 hStripVsPlaneMinderCh->Fill(pl,st,minderCh);
03227 hStripVsPlaneLed->Fill(pl,st,led);
03228 hStripVsPlaneEnt->Fill(pl,st,1.);
03229 }
03230 else if (se==1){
03231
03232 hStripVsPlane2Pix->Fill(pl,st,pix);
03233 hStripVsPlane2Spot->Fill(pl,st,spot);
03234 hStripVsPlane2Crate->Fill(pl,st,crate);
03235 hStripVsPlane2Varc->Fill(pl,st,varc);
03236 hStripVsPlane2Vmm->Fill(pl,st,vmm);
03237 hStripVsPlane2Vfb->Fill(pl,st,vfb);
03238 hStripVsPlane2VaChip->Fill(pl,st,vaChip);
03239 hStripVsPlane2Ch->Fill(pl,st,ch);
03240 hStripVsPlane2GeoAdd->Fill(pl,st,geoAdd);
03241 hStripVsPlane2MasterCh->Fill(pl,st,masterCh);
03242 hStripVsPlane2MinderCh->Fill(pl,st,minderCh);
03243 hStripVsPlane2Led->Fill(pl,st,led);
03244 hStripVsPlane2Ent->Fill(pl,st,1.);
03245 }
03246 }
03247 }
03248 }
03249
03253
03254
03255 gStyle->SetOptStat(0);
03256
03257 Int_t draw=1;
03258 if (draw==1){
03259 TCanvas *cStripVsPlaneLed=new TCanvas
03260 ("cStripVsPlaneLed","StripVsPlane: Led",0,0,1000,800);
03261 cStripVsPlaneLed->SetFillColor(0);
03262 cStripVsPlaneLed->cd();
03263 hStripVsPlaneLed->Draw("colz");
03264
03265 TCanvas *cStripVsPlanePix=new TCanvas
03266 ("cStripVsPlanePix","StripVsPlane: Pixel",0,0,1000,800);
03267 cStripVsPlanePix->SetFillColor(0);
03268 cStripVsPlanePix->cd();
03269 hStripVsPlanePix->Draw("textcolz");
03270
03271 TCanvas *cStripVsPlaneCrate=new TCanvas
03272 ("cStripVsPlaneCrate","StripVsPlane: Crate",0,0,1000,800);
03273 cStripVsPlaneCrate->SetFillColor(0);
03274 cStripVsPlaneCrate->cd();
03275 hStripVsPlaneCrate->Draw("textcolz");
03276
03277 TCanvas *cStripVsPlaneVarc=new TCanvas
03278 ("cStripVsPlaneVarc","StripVsPlane: Varc",0,0,1000,800);
03279 cStripVsPlaneVarc->SetFillColor(0);
03280 cStripVsPlaneVarc->cd();
03281 hStripVsPlaneVarc->Draw("textcolz");
03282
03283 TCanvas *cStripVsPlaneVmm=new TCanvas
03284 ("cStripVsPlaneVmm","StripVsPlane: Vmm",0,0,1000,800);
03285 cStripVsPlaneVmm->SetFillColor(0);
03286 cStripVsPlaneVmm->cd();
03287 hStripVsPlaneVmm->Draw("textcolz");
03288
03289 TCanvas *cStripVsPlaneVfb=new TCanvas
03290 ("cStripVsPlaneVfb","StripVsPlane: Vfb",0,0,1000,800);
03291 cStripVsPlaneVfb->SetFillColor(0);
03292 cStripVsPlaneVfb->cd();
03293 hStripVsPlaneVfb->Draw("textcolz");
03294
03295 TCanvas *cStripVsPlaneVaChip=new TCanvas
03296 ("cStripVsPlaneVaChip","StripVsPlane: VaChip",0,0,1000,800);
03297 cStripVsPlaneVaChip->SetFillColor(0);
03298 cStripVsPlaneVaChip->cd();
03299 hStripVsPlaneVaChip->Draw("textcolz");
03300
03301 TCanvas *cStripVsPlaneCh=new TCanvas
03302 ("cStripVsPlaneCh","StripVsPlane: Ch",0,0,1000,800);
03303 cStripVsPlaneCh->SetFillColor(0);
03304 cStripVsPlaneCh->cd();
03305 hStripVsPlaneCh->Draw("textcolz");
03306
03307 TCanvas *cStripVsPlaneGeoAdd=new TCanvas
03308 ("cStripVsPlaneGeoAdd","StripVsPlane: GeoAdd",0,0,1000,800);
03309 cStripVsPlaneGeoAdd->SetFillColor(0);
03310 cStripVsPlaneGeoAdd->cd();
03311 hStripVsPlaneGeoAdd->Draw("textcolz");
03312
03313 TCanvas *cStripVsPlaneMasterCh=new TCanvas
03314 ("cStripVsPlaneMasterCh","StripVsPlane: Master Channel",
03315 0,0,1000,800);
03316 cStripVsPlaneMasterCh->SetFillColor(0);
03317 cStripVsPlaneMasterCh->cd();
03318 hStripVsPlaneMasterCh->Draw("textcolz");
03319
03320 }
03321
03322 TCanvas *cStripVsPlaneMinderCh=new TCanvas
03323 ("cStripVsPlaneMinderCh","StripVsPlane: MinderCh",0,0,1000,800);
03324 cStripVsPlaneMinderCh->SetFillColor(0);
03325 cStripVsPlaneMinderCh->cd();
03326 hStripVsPlaneMinderCh->Draw("textcolz");
03327
03328 TCanvas *cStripVsPlaneSpot=new TCanvas
03329 ("cStripVsPlaneSpot","StripVsPlane: Spot",0,0,1000,800);
03330 cStripVsPlaneSpot->SetFillColor(0);
03331 cStripVsPlaneSpot->cd();
03332 hStripVsPlaneSpot->Draw("textcolz");
03333
03334 TCanvas *cStripVsPlaneEnt=new TCanvas
03335 ("cStripVsPlaneEnt","StripVsPlane: NumEntries",0,0,1000,800);
03336 cStripVsPlaneEnt->SetFillColor(0);
03337 cStripVsPlaneEnt->cd();
03338 hStripVsPlaneEnt->Draw("textcolz");
03339
03340
03342
03344
03345 TCanvas *cStripVsPlane2Led=new TCanvas
03346 ("cStripVsPlane2Led","StripVsPlane2: Led",0,0,1000,800);
03347 cStripVsPlane2Led->SetFillColor(0);
03348 cStripVsPlane2Led->cd();
03349 hStripVsPlane2Led->Draw("colz");
03350
03351 TCanvas *cStripVsPlane2Pix=new TCanvas
03352 ("cStripVsPlane2Pix","StripVsPlane2: Pixel",0,0,1000,800);
03353 cStripVsPlane2Pix->SetFillColor(0);
03354 cStripVsPlane2Pix->cd();
03355 hStripVsPlane2Pix->Draw("textcolz");
03356
03357 TCanvas *cStripVsPlane2Crate=new TCanvas
03358 ("cStripVsPlane2Crate","StripVsPlane2: Crate",0,0,1000,800);
03359 cStripVsPlane2Crate->SetFillColor(0);
03360 cStripVsPlane2Crate->cd();
03361 hStripVsPlane2Crate->Draw("textcolz");
03362
03363 TCanvas *cStripVsPlane2Varc=new TCanvas
03364 ("cStripVsPlane2Varc","StripVsPlane2: Varc",0,0,1000,800);
03365 cStripVsPlane2Varc->SetFillColor(0);
03366 cStripVsPlane2Varc->cd();
03367 hStripVsPlane2Varc->Draw("textcolz");
03368
03369 TCanvas *cStripVsPlane2Vmm=new TCanvas
03370 ("cStripVsPlane2Vmm","StripVsPlane2: Vmm",0,0,1000,800);
03371 cStripVsPlane2Vmm->SetFillColor(0);
03372 cStripVsPlane2Vmm->cd();
03373 hStripVsPlane2Vmm->Draw("textcolz");
03374
03375 TCanvas *cStripVsPlane2Vfb=new TCanvas
03376 ("cStripVsPlane2Vfb","StripVsPlane2: Vfb",0,0,1000,800);
03377 cStripVsPlane2Vfb->SetFillColor(0);
03378 cStripVsPlane2Vfb->cd();
03379 hStripVsPlane2Vfb->Draw("textcolz");
03380
03381 TCanvas *cStripVsPlane2VaChip=new TCanvas
03382 ("cStripVsPlane2VaChip","StripVsPlane2: VaChip",0,0,1000,800);
03383 cStripVsPlane2VaChip->SetFillColor(0);
03384 cStripVsPlane2VaChip->cd();
03385 hStripVsPlane2VaChip->Draw("textcolz");
03386
03387 TCanvas *cStripVsPlane2Ch=new TCanvas
03388 ("cStripVsPlane2Ch","StripVsPlane2: Ch",0,0,1000,800);
03389 cStripVsPlane2Ch->SetFillColor(0);
03390 cStripVsPlane2Ch->cd();
03391 hStripVsPlane2Ch->Draw("textcolz");
03392
03393 TCanvas *cStripVsPlane2GeoAdd=new TCanvas
03394 ("cStripVsPlane2GeoAdd","StripVsPlane2: GeoAdd",0,0,1000,800);
03395 cStripVsPlane2GeoAdd->SetFillColor(0);
03396 cStripVsPlane2GeoAdd->cd();
03397 hStripVsPlane2GeoAdd->Draw("textcolz");
03398
03399 TCanvas *cStripVsPlane2MasterCh=new TCanvas
03400 ("cStripVsPlane2MasterCh","StripVsPlane2: Master Channel",
03401 0,0,1000,800);
03402 cStripVsPlane2MasterCh->SetFillColor(0);
03403 cStripVsPlane2MasterCh->cd();
03404 hStripVsPlane2MasterCh->Draw("textcolz");
03405
03406 TCanvas *cStripVsPlane2MinderCh=new TCanvas
03407 ("cStripVsPlane2MinderCh","StripVsPlane2: MinderCh",0,0,1000,800);
03408 cStripVsPlane2MinderCh->SetFillColor(0);
03409 cStripVsPlane2MinderCh->cd();
03410 hStripVsPlane2MinderCh->Draw("textcolz");
03411
03412 TCanvas *cStripVsPlane2Spot=new TCanvas
03413 ("cStripVsPlane2Spot","StripVsPlane2: Spot",0,0,1000,800);
03414 cStripVsPlane2Spot->SetFillColor(0);
03415 cStripVsPlane2Spot->cd();
03416 hStripVsPlane2Spot->Draw("textcolz");
03417
03418 TCanvas *cStripVsPlane2Ent=new TCanvas
03419 ("cStripVsPlane2Ent","StripVsPlane2: NumEntries",0,0,1000,800);
03420 cStripVsPlane2Ent->SetFillColor(0);
03421 cStripVsPlane2Ent->cd();
03422 hStripVsPlane2Ent->Draw("textcolz");
03423
03424 MSG("LIPlexMaps",Msg::kInfo)
03425 <<endl<<" ** Finished the PlotPlexStripMap method ** "
03426 <<endl;
03427 }
03428
03429
03430
03431 void LIPlexMaps::MakePinPlexTables()
03432 {
03433 MSG("LIPlexMaps",Msg::kInfo)
03434 <<endl<<" ** Running the MakePinPlexTables() method... ** "
03435 <<endl;
03436
03437
03438
03439
03440 VldTimeStamp farpinstart = VldTimeStamp(2000,1,1,12,0,0);
03441 VldTimeStamp farpinend = VldTimeStamp(2010,1,1,12,0,0);
03442 VldRange farpinvr(Detector::kFar,SimFlag::kData,farpinstart,
03443 farpinend,"LIPlexMaps");
03444 VldTimeStamp create;
03445 VldContext vc(Detector::kFar,SimFlag::kData,create);
03446 PlexHandle plexHandle(vc);
03447
03448 for(Int_t pb=0;pb<NUMPULSERBOXES;pb++){
03449 for(Int_t led=1;led<=LASTPULSERBOX;led++){
03450
03451 PlexLedId ledId(Detector::kFar,pb,led);
03452
03453 int aggNo = 0x7ff & ledId.GetEncoded();
03454
03455 DbiWriter<PlexPinDiodeToLed> writer(farpinvr,aggNo,0,create);
03456
03457 std::pair<PlexPinDiodeId,PlexPinDiodeId> newPins=fLookup.
03458 GetPinDiodeIds(plexHandle,ledId.GetLedInBox());
03459
03460 PlexPinDiodeToLed hpin2led(newPins.first.GetDetector(),
03461 newPins.first.GetElecType(),
03462 newPins.first.GetEastWest(),
03463 newPins.first.GetRackLevel(),
03464 newPins.first.GetRackBay(),
03465 newPins.first.GetInRack(),
03466 newPins.first.GetInBox(),
03467 newPins.first.GetGain(),
03468 ledId.GetPulserBox(),
03469 ledId.GetLedInBox());
03470 PlexPinDiodeToLed lpin2led(newPins.second.GetDetector(),
03471 newPins.second.GetElecType(),
03472 newPins.second.GetEastWest(),
03473 newPins.second.GetRackLevel(),
03474 newPins.second.GetRackBay(),
03475 newPins.second.GetInRack(),
03476 newPins.second.GetInBox(),
03477 newPins.second.GetGain(),
03478 ledId.GetPulserBox(),
03479 ledId.GetLedInBox());
03480 writer <<hpin2led;
03481 writer <<lpin2led;
03482
03483 }
03484 }
03485
03486 MSG("LIPlexMaps",Msg::kInfo)
03487 <<endl<<" ** Finished the MakePinPlexTables() method... ** "
03488 <<endl;
03489 }
03490
03491
03492
03493 void LIPlexMaps::MakeCalAdcToPe(string sGainsFileName,
03494 Detector::Detector_t det,
03495 SimFlag::ESimFlag simFlag,
03496 VldTimeStamp vldStart,
03497 VldTimeStamp vldEnd,
03498 Int_t aggNo,
03499 Int_t task,
03500 Int_t aggStat[484],
03501 VldTimeStamp creationDate,
03502 std::string dbName,
03503 std::string sLogComment,
03504 Int_t gainTooHigh,Int_t gainCeiling,
03505 Bool_t writeToDb)
03506 {
03507 MSG("LIPlexMaps",Msg::kInfo)
03508 <<endl<<" ** Running the MakeCalAdcToPe() method... **"<<endl;
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548
03549
03550
03551
03552
03553
03554
03555
03556
03557
03558
03559
03560
03561
03562
03563 this->SetDetector(det);
03564
03565
03566 MSG("LIPlexMaps",Msg::kInfo)<<"Getting plex handle..."<<endl;
03567 VldContext vldCtx(det,SimFlag::kData,creationDate);
03568 PlexHandle plexHandle(vldCtx);
03569
03570 gStyle->SetOptStat(1111111);
03571
03572 TH1F *hGain=new TH1F("hGain","PMT Gains",300,-1,gainTooHigh);
03573 hGain->GetXaxis()->SetTitle("PMT Gain");
03574 hGain->GetXaxis()->CenterTitle();
03575 hGain->GetYaxis()->SetTitle("");
03576 hGain->GetYaxis()->CenterTitle();
03577 hGain->SetLineColor(2);
03578 hGain->SetFillStyle(3015);
03579 hGain->SetFillColor(2);
03580 hGain->SetLineWidth(2);
03581
03582
03583 TH1F *hGainHighPmt=new TH1F("hGainHighPmt","PMT Gains: HighPmts",
03584 100,gainTooHigh,gainCeiling+5);
03585 hGainHighPmt->GetXaxis()->SetTitle("PMT Gain");
03586 hGainHighPmt->GetXaxis()->CenterTitle();
03587 hGainHighPmt->GetYaxis()->SetTitle("");
03588 hGainHighPmt->GetYaxis()->CenterTitle();
03589 hGainHighPmt->SetLineColor(2);
03590 hGainHighPmt->SetFillStyle(3015);
03591 hGainHighPmt->SetFillColor(2);
03592 hGainHighPmt->SetLineWidth(2);
03593
03594
03595 TH1F *hGainCrazyHighPmt=new TH1F("hGainCrazyHighPmt",
03596 "PMT Gains: CrazyHighPmts",
03597 200,gainCeiling,gainCeiling+100);
03598 hGainCrazyHighPmt->GetXaxis()->SetTitle("PMT Gain");
03599 hGainCrazyHighPmt->GetXaxis()->CenterTitle();
03600 hGainCrazyHighPmt->GetYaxis()->SetTitle("");
03601 hGainCrazyHighPmt->GetYaxis()->CenterTitle();
03602 hGainCrazyHighPmt->SetLineColor(2);
03603 hGainCrazyHighPmt->SetFillStyle(3015);
03604 hGainCrazyHighPmt->SetFillColor(2);
03605 hGainCrazyHighPmt->SetLineWidth(2);
03606 hGainCrazyHighPmt->SetBit(TH1::kCanRebin);
03607
03608 TH1F *hGainAvDet=new TH1F("hGainAvDet","PMT Gains in Av Detector PMT",
03609 100,55,85);
03610 hGainAvDet->GetXaxis()->SetTitle("PMT Gain");
03611 hGainAvDet->GetXaxis()->CenterTitle();
03612 hGainAvDet->GetYaxis()->SetTitle("");
03613 hGainAvDet->GetYaxis()->CenterTitle();
03614 hGainAvDet->SetLineColor(2);
03615 hGainAvDet->SetFillStyle(3015);
03616 hGainAvDet->SetFillColor(2);
03617 hGainAvDet->SetLineWidth(2);
03618 hGainAvDet->SetBit(TH1::kCanRebin);
03619
03620 TH1F *hGainErr=new TH1F("hGainErr","PMT GainErrs",
03621 400,0,110);
03622 hGainErr->GetXaxis()->SetTitle("PMT GainErr");
03623 hGainErr->GetXaxis()->CenterTitle();
03624 hGainErr->GetYaxis()->SetTitle("");
03625 hGainErr->GetYaxis()->CenterTitle();
03626 hGainErr->SetLineColor(2);
03627 hGainErr->SetFillStyle(3015);
03628 hGainErr->SetFillColor(2);
03629 hGainErr->SetLineWidth(5);
03630 hGainErr->SetBit(TH1::kCanRebin);
03631
03632 TH1F *hGainErrZoom=new TH1F("hGainErrZoom","PMT GainErrs (Zoomed)",
03633 400,0,10);
03634 hGainErrZoom->GetXaxis()->SetTitle("PMT GainErrZoom");
03635 hGainErrZoom->GetXaxis()->CenterTitle();
03636 hGainErrZoom->GetYaxis()->SetTitle("");
03637 hGainErrZoom->GetYaxis()->CenterTitle();
03638 hGainErrZoom->SetLineColor(2);
03639 hGainErrZoom->SetFillStyle(3015);
03640 hGainErrZoom->SetFillColor(2);
03641 hGainErrZoom->SetLineWidth(2);
03642
03643
03644 TH1F *hGainErrFract=new TH1F("hGainErrFract",
03645 "Fractional PMT GainErrs",
03646 800,0.005,0.05);
03647 hGainErrFract->GetXaxis()->SetTitle("Fractional PMT GainErr");
03648 hGainErrFract->GetXaxis()->CenterTitle();
03649 hGainErrFract->GetYaxis()->SetTitle("");
03650 hGainErrFract->GetYaxis()->CenterTitle();
03651 hGainErrFract->SetLineColor(2);
03652 hGainErrFract->SetFillStyle(3015);
03653 hGainErrFract->SetFillColor(2);
03654 hGainErrFract->SetLineWidth(2);
03655
03656
03657 TH1F *hSPEWidth=new TH1F("hSPEWidth","PMT SPEWidths",
03658 300,0,gainCeiling/2+5);
03659 hSPEWidth->GetXaxis()->SetTitle("PMT SPEWidth");
03660 hSPEWidth->GetXaxis()->CenterTitle();
03661 hSPEWidth->GetYaxis()->SetTitle("");
03662 hSPEWidth->GetYaxis()->CenterTitle();
03663 hSPEWidth->SetLineColor(2);
03664 hSPEWidth->SetFillStyle(3015);
03665 hSPEWidth->SetFillColor(2);
03666 hSPEWidth->SetLineWidth(2);
03667
03668
03669 Int_t* planeMax=new Int_t[NUMCRATES];
03670 Int_t* planeMin=new Int_t[NUMCRATES];
03671 fLookup.SetPbPlanes(planeMin,planeMax,det);
03672
03673 const Int_t firstStripBin=FIRSTSTRIP-8;
03674 const Int_t lastStripBin=LASTSTRIP+9;
03675 const Int_t bins=lastStripBin-firstStripBin;
03676
03677 TH2F **hStripVsPlaneGain=0;
03678 hStripVsPlaneGain= new TH2F*[NUMCRATES];
03679 for (Int_t i=0;i<NUMCRATES;i++){
03680 string sPb=Form("%d",i);
03681 fS="Gains (Crate "+sPb+")";
03682 hStripVsPlaneGain[i]=new TH2F(fS.c_str(),fS.c_str(),
03683 planeMax[i]-planeMin[i],
03684 planeMin[i],planeMax[i],
03685 bins,firstStripBin,lastStripBin);
03686 hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
03687 hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
03688 hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
03689 hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
03690 hStripVsPlaneGain[i]->SetFillColor(0);
03691
03692 }
03693
03694 TH2F **hStripVsPlaneGainErr=0;
03695 hStripVsPlaneGainErr= new TH2F*[NUMCRATES];
03696 for (Int_t i=0;i<NUMCRATES;i++){
03697 string sPb=Form("%d",i);
03698 fS="Gain Errors (Crate "+sPb+")";
03699 hStripVsPlaneGainErr[i]=new TH2F(fS.c_str(),fS.c_str(),
03700 planeMax[i]-planeMin[i],
03701 planeMin[i],planeMax[i],
03702 bins,firstStripBin,lastStripBin);
03703 hStripVsPlaneGainErr[i]->GetXaxis()->SetTitle("Plane");
03704 hStripVsPlaneGainErr[i]->GetXaxis()->CenterTitle();
03705 hStripVsPlaneGainErr[i]->GetYaxis()->SetTitle("Strip");
03706 hStripVsPlaneGainErr[i]->GetYaxis()->CenterTitle();
03707 hStripVsPlaneGainErr[i]->SetFillColor(0);
03708
03709 }
03710
03711 TH2F **hStripVsPlaneSPEWidth=0;
03712 hStripVsPlaneSPEWidth= new TH2F*[NUMCRATES];
03713 for (Int_t i=0;i<NUMCRATES;i++){
03714 string sPb=Form("%d",i);
03715 fS="Single PE Width (Crate "+sPb+")";
03716 hStripVsPlaneSPEWidth[i]=new TH2F(fS.c_str(),fS.c_str(),
03717 planeMax[i]-planeMin[i],
03718 planeMin[i],planeMax[i],
03719 bins,firstStripBin,lastStripBin);
03720 hStripVsPlaneSPEWidth[i]->GetXaxis()->SetTitle("Plane");
03721 hStripVsPlaneSPEWidth[i]->GetXaxis()->CenterTitle();
03722 hStripVsPlaneSPEWidth[i]->GetYaxis()->SetTitle("Strip");
03723 hStripVsPlaneSPEWidth[i]->GetYaxis()->CenterTitle();
03724 hStripVsPlaneSPEWidth[i]->SetFillColor(0);
03725
03726 }
03727
03728 vector<Float_t> vGains(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03729 vector<Float_t> vGainErrs(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03730 vector<Float_t> vSPEWidths(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03731 vector<Float_t> vSPEWidthErrs(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03732 map<UInt_t,LIPmt> pmts;
03733 LIPmt avDetPmt;
03734 avDetPmt.Initialise(NUMPIXELS,NUMPIXELSPOTS);
03735
03736
03737 Double_t gainAvDet=0;
03738 Double_t gainErrAvDet=0;
03739 Int_t gainNum=0;
03740
03741 Float_t gainErrUnknownPixelSpot=10;
03742 Float_t gainErrUnknownPixel=40;
03743 Float_t gainErrUnknownNN=50;
03744 Float_t gainErrUnknownPmt=100;
03745 Float_t gainErrTooHighGain=90;
03746 Float_t SPEWidthFraction=0.5;
03747
03748
03749 MSG("LIPlexMaps",Msg::kInfo)
03750 <<"Opening file "<<sGainsFileName<<"..."<<endl;
03751 ifstream gainsFile(sGainsFileName.c_str());
03752
03753
03754 if (gainsFile){
03755
03756
03757 Int_t plane=-1;
03758 Int_t strip=-1;
03759 Int_t end=-1;
03760 Float_t gain=-1;
03761 Float_t gainErr=-1;
03762 Float_t SPEWidth=-1;
03763
03764
03765 Int_t lastPlane=-1;
03766
03767
03768 while(gainsFile>>plane>>strip>>end>>gain>>gainErr>>SPEWidth) {
03769
03770 Int_t seIndex=plane*NUMSTRIPS*NUMENDS+strip*NUMENDS+end-1;
03771
03772 if (plane<FIRSTPLANE || plane>LASTPLANE || strip<FIRSTSTRIP ||
03773 strip>LASTSTRIP || end<FIRSTEND || end>LASTEND) {
03774 MSG("LIPlexMaps",Msg::kWarning)
03775 <<"Plane, strip or stripend are out of range: plane="<<plane
03776 <<", strip="<<strip<<", end="<<end<<endl
03777 <<"Detector type is set to "<<Detector::AsString(det)
03778 <<endl
03779 <<"Program will exit here..."<<endl;
03780 exit(1);
03781 }
03782
03783
03784 if (plane!=lastPlane && plane%20==0) {
03785 MSG("LIPlexMaps",Msg::kInfo)<<"New plane="<<plane<<endl;
03786 }
03787 else if (plane!=lastPlane){
03788 MSG("LIPlexMaps",Msg::kDebug)<<"New plane="<<plane<<endl;
03789 }
03790 lastPlane=plane;
03791
03792
03793 vGains[seIndex]=gain;
03794 vGainErrs[seIndex]=gainErr;
03795 vSPEWidths[seIndex]=SPEWidth;
03796 vSPEWidthErrs[seIndex]=0.5;
03797
03798
03799 if (gain>-1 && gain<2){
03800 MSG("LIPlexMaps",Msg::kWarning)
03801 <<"What sort of gain is this? gain="<<gain<<endl;
03802 }
03803
03804
03805 PlexStripEndId seid(det,plane,strip,
03806 static_cast<StripEnd::EStripEnd>(end));
03807
03808 PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
03809
03810 MSG("LIPlexMaps",Msg::kVerbose)
03811 <<"("<<plane<<":"<<strip<<":"<<end<<") "
03812 <<pixSpotId.AsString()<<endl;
03813
03814 UInt_t pmtKey=pixSpotId.GetUniquePmtEncodedValue();
03815
03816 pmts[pmtKey].Initialise(NUMPIXELS,NUMPIXELSPOTS);
03817
03818
03819 if (gain>-1){
03820 gainErrAvDet+=gainErr;
03821 gainAvDet+=gain;
03822 gainNum++;
03823
03824 if (pixSpotId.GetSpot()<1){
03825 seid.Print();
03826 pixSpotId.Print();
03827 }
03828
03829 pmts[pmtKey].SetPoint(pixSpotId.GetPixel(),pixSpotId.GetSpot(),
03830 gain);
03831
03832 avDetPmt.AddMultiPoint(pixSpotId.GetPixel(),pixSpotId.GetSpot(),
03833 gain);
03834 }
03835 }
03836 }
03837 else{
03838 MSG("LIPlexMaps",Msg::kInfo)
03839 <<"Can't open file "<<sGainsFileName<<endl
03840 <<"Exiting here..."<<endl;
03841 exit(1);
03842 }
03843
03844
03845 MSG("LIPlexMaps",Msg::kInfo) << "All detector gain="<<gainAvDet<<", gainErr="<<gainErrAvDet<<endl;
03846 if (gainNum!=0) gainAvDet/=gainNum;
03847 if (gainNum!=0) gainErrAvDet/=gainNum;
03848 MSG("LIPlexMaps",Msg::kInfo)
03849 <<"AverageDetector: gain= "<<gainAvDet<<" gainErr= "<<gainErrAvDet
03850 <<" gainNum= "<<gainNum
03851 <<" Npmts= "<<pmts.size()<<endl;
03852
03853 avDetPmt.FillGainsHisto(hGainAvDet);
03854
03856
03858
03859 Int_t pixCounter=0;
03860 Int_t nnCounter=0;
03861 Int_t pmtCounter=0;
03862 Int_t detCounter=0;
03863 Int_t gainHighCounter=0;
03864 Int_t gainCappedCounter=0;
03865 Int_t totalCounter=0;
03866 Int_t goodCounter=0;
03867
03868 Int_t pixgainHighCounter=0;
03869 Int_t pixgainCappedCounter=0;
03870 Int_t nngainHighCounter=0;
03871 Int_t nngainCappedCounter=0;
03872 Int_t pmtgainHighCounter=0;
03873 Int_t pmtgainCappedCounter=0;
03874 Int_t detgainHighCounter=0;
03875 Int_t detgainCappedCounter=0;
03876
03877
03878 char *gaindump_filename = getenv("GAIN_DUMP_FILE");
03879
03880
03881 ofstream gaindump(gaindump_filename);
03882 if (gaindump.is_open()) {
03883 MSG("LIPlexMaps",Msg::kInfo) << "Dumping gain values to " << gaindump_filename << endl;
03884
03885 gaindump << "#"
03886 << setw(3) << "Pl" << " "
03887 << setw(3) << "Str" << " "
03888 << setw(3) << "End" << " "
03889 << setw(4) << "Agg" << " "
03890 << setw(6) << "SEID" << " "
03891 << setw(9) << "Gain" << " "
03892 << setw(9) << "Error"
03893 << "\n";
03894
03895 } else {
03896 MSG("LIPlexMaps",Msg::kInfo) << "Not writing to gain dump." << endl;
03897 }
03898
03899
03900 VldRange vr(det,simFlag,vldStart,vldEnd,
03901 "LISummary/LIPlexMaps::MakeCalAdcToPe");
03902
03903 MSG("LIPlexMaps",Msg::kInfo)
03904 <<"Using Validity Range: "<<vr.AsString()<<endl;
03905
03906 MSG("LIPlexMaps",Msg::kInfo)
03907 <<endl<<"Log comment="<<sLogComment<<endl<<endl;
03908
03909
03910 DbiWriter<CalADCtoPE> writer(vr,aggNo,task,creationDate,dbName,
03911 sLogComment);
03912
03913
03914 Int_t NUMAGG = NUMCRATES; if(task==1) { NUMAGG = 484; if(det==1) NUMAGG = 194; }
03915
03916
03917 for(Int_t agg=0;agg<NUMAGG;agg++){
03918 if(aggStat[agg]<0) continue;
03919
03920
03921 if(aggNo==-1) agg = NUMAGG-1;
03922 DbiWriter<CalADCtoPEs> writers(vr,agg,task,creationDate,dbName,sLogComment);
03923
03924 Int_t pixCounter2=0;
03925 Int_t nnCounter2=0;
03926 Int_t pmtCounter2=0;
03927 Int_t detCounter2=0;
03928 Int_t gainHighCounter2=0;
03929 Int_t gainCappedCounter2=0;
03930 Int_t totalCounter2=0;
03931 Int_t goodCounter2=0;
03932
03933
03934 for(Int_t pl=FIRSTSCINTPLANE;pl<=LASTSCINTPLANE;pl++) {
03935 for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++) {
03936 for(Int_t end=FIRSTEND;end<=SECONDEND;end++) {
03937
03938
03939 if ((pl==SM1BOOKEND || pl==SM2BOOKEND) &&
03940 det==Detector::kFar) continue;
03941
03942
03943
03944
03945
03946 Int_t seIndex=pl*NUMSTRIPS*NUMENDS+st*NUMENDS+end-1;
03947
03948
03949 PlexStripEndId seid(det,pl,st,
03950 static_cast<StripEnd::EStripEnd>(end));
03951
03952
03953 if (!seid.IsValid() ) continue;
03954
03955
03956
03957
03958 if (det==Detector::kNear) {
03959 if (((pl-1)%5) && (pl%2) && st>63) continue;
03960 if (((pl-1)%5) && (pl%2)==0 && st<4 ) continue;
03961 }
03962
03963
03964 Int_t crate=plexHandle.GetRawChannelId(seid).GetCrate();
03965 PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
03966 if (aggNo!=-1 && ((task==0 && crate!=agg) || (task==1 && static_cast<Int_t>(pixSpotId.GetNumericMuxBox())!=LILookup::GetNumericMuxBox(agg)))) continue;
03967
03968
03969 if(vGains[seIndex]==-1){
03970
03971 Int_t pmtKey=pixSpotId.GetUniquePmtEncodedValue();
03972
03973
03974 Double_t pmtGain=pmts[pmtKey].GetAvPmtGain();
03975 Int_t pmtNum=pmts[pmtKey].GetPmtNum();
03976 Double_t pixelGain=pmts[pmtKey].GetPixelGain(pixSpotId.GetPixel());
03977 Int_t pixelNum=pmts[pmtKey].GetPixelNum(pixSpotId.GetPixel());
03978 Double_t nnGain=pmts[pmtKey].GetNearestNeighboursAvGain(pixSpotId.GetPixel());
03979 Int_t nnNum=pmts[pmtKey].GetNearestNeighboursNum(pixSpotId.GetPixel());
03980
03981 Bool_t pixGood=false;
03982 Bool_t nnGood=false;
03983 Bool_t pmtGood=false;
03984
03985
03986 if (pixelNum>0 && pixelGain>0) pixGood=true;
03987 if (nnNum>0 && nnGain>0) nnGood=true;
03988 if (pmtNum>0 && pmtGain>0) pmtGood=true;
03989
03990
03991 if (pixGood){
03992 pixCounter++; pixCounter2++;
03993 vGains[seIndex]=pixelGain;
03994 vGainErrs[seIndex]=gainErrUnknownPixelSpot;
03995 vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
03996 if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)) {
03997 MSG("LIPlexMaps",Msg::kInfo)
03998 <<"("<<pl<<":"<<st<<":"<<end<<")"
03999 <<" No Data: Setting gain to be average of pixel ("
04000 <<vGains[seIndex]<<")"<<endl
04001 <<" pixGain="<<pixelGain<<" (N="<<pixelNum
04002 <<"), nnGain="<<nnGain<<" (N="<<nnNum
04003 <<"), pmtGain="<<pmtGain<<", (N="<<pmtNum<<")"<<endl;
04004 }
04005 } else if (nnGood) {
04006 nnCounter++; nnCounter2++;
04007 vGains[seIndex]=nnGain;
04008 vGainErrs[seIndex]=gainErrUnknownPixel;
04009 vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
04010 MSG("LIPlexMaps",Msg::kInfo)
04011 <<"("<<pl<<":"<<st<<":"<<end<<")"
04012 <<" No Data: Setting gain to be average of NN ("
04013 <<vGains[seIndex]<<")"<<endl
04014 <<" pixGain="<<pixelGain<<" (N="<<pixelNum
04015 <<"), nnGain="<<nnGain<<" (N="<<nnNum
04016 <<"), pmtGain="<<pmtGain<<", (N="<<pmtNum<<")"<<endl;
04017 } else if (pmtGood) {
04018 pmtCounter++; pmtCounter2++;
04019 vGains[seIndex]=pmtGain;
04020 vGainErrs[seIndex]=gainErrUnknownNN;
04021 vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
04022 MSG("LIPlexMaps",Msg::kInfo)
04023 <<"("<<pl<<":"<<st<<":"<<end<<")"
04024 <<" No Data: Setting gain to be average of pmt ("
04025 <<vGains[seIndex]<<")"<<endl
04026 <<" pixGain="<<pixelGain<<" (N="<<pixelNum
04027 <<"), nnGain="<<nnGain<<" (N="<<nnNum
04028 <<"), pmtGain="<<pmtGain<<", (N="<<pmtNum<<")"<<endl;
04029 } else {
04030 detCounter++; detCounter2++;
04031
04032 Double_t avDetPmtGain=avDetPmt.GetAvPmtGain();
04033 Int_t avDetPmtNum=avDetPmt.GetPmtNum();
04034 Double_t avDetPmtPixelGain=avDetPmt.
04035 GetPixelGain(pixSpotId.GetPixel());
04036 Int_t avDetPmtPixelNum=avDetPmt.
04037 GetPixelNum(pixSpotId.GetPixel());
04038
04039 Double_t avDetPmtSpotGain=avDetPmt.
04040 GetGain(pixSpotId.GetPixel(),pixSpotId.GetSpot());
04041
04042 vGains[seIndex]=avDetPmtSpotGain;
04043 vGainErrs[seIndex]=gainErrUnknownPmt;
04044 vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
04045 MSG("LIPlexMaps",Msg::kInfo)
04046 <<"("<<pl<<":"<<st<<":"<<end<<")"
04047 <<" No Data: Setting gain to same spot on average pmt ("
04048 <<vGains[seIndex]<<")"<<endl
04049 <<" pixGain="<<avDetPmtPixelGain
04050 <<", pixNum="<<avDetPmtPixelNum
04051 <<", pmtGain="<<avDetPmtGain
04052 <<", pmtNum="<<avDetPmtNum<<endl;
04053 }
04054 } else {
04055 goodCounter++; goodCounter2++;
04056 }
04057
04058
04059 if(vGains[seIndex]>gainTooHigh){
04060
04061 if(vGainErrs[seIndex]!=gainErrUnknownPixelSpot && vGainErrs[seIndex]!=gainErrUnknownPixel &&
04062 vGainErrs[seIndex]!=gainErrUnknownNN && vGainErrs[seIndex]!=gainErrUnknownPmt ) {
04063
04064
04065 goodCounter--; goodCounter2--;
04066
04067 gainHighCounter++; gainHighCounter2++;
04068
04069 }
04070 if(vGainErrs[seIndex]==gainErrUnknownPixelSpot) {
04071 pixgainHighCounter++; if (vGains[seIndex]>gainCeiling) pixgainCappedCounter++;
04072 }
04073 if(vGainErrs[seIndex]==gainErrUnknownPixel) {
04074 nngainHighCounter++; if (vGains[seIndex]>gainCeiling) nngainCappedCounter++;
04075 }
04076 if(vGainErrs[seIndex]==gainErrUnknownNN) {
04077 pmtgainHighCounter++; if (vGains[seIndex]>gainCeiling) pmtgainCappedCounter++;
04078 }
04079 if(vGainErrs[seIndex]==gainErrUnknownPmt) {
04080 detgainHighCounter++; if (vGains[seIndex]>gainCeiling) detgainCappedCounter++;
04081 }
04082
04083 Int_t pmtKey=pixSpotId.GetUniquePmtEncodedValue();
04084
04085
04086 Double_t pmtGain=pmts[pmtKey].GetAvPmtGain();
04087 Int_t pmtNum=pmts[pmtKey].GetPmtNum();
04088 Double_t pixelGain=pmts[pmtKey].GetPixelGain(pixSpotId.
04089 GetPixel());
04090 Int_t pixelNum=pmts[pmtKey].GetPixelNum(pixSpotId.GetPixel());
04091
04092
04093 if (vGains[seIndex]>gainCeiling){
04094 hGainCrazyHighPmt->Fill(vGains[seIndex]);
04095
04096 if(vGainErrs[seIndex]!=gainErrUnknownPixelSpot && vGainErrs[seIndex]!=gainErrUnknownPixel &&
04097 vGainErrs[seIndex]!=gainErrUnknownNN && vGainErrs[seIndex]!=gainErrUnknownPmt )
04098 {
04099 gainCappedCounter++; gainCappedCounter2++;
04100 }
04101
04102 Float_t oldGain=vGains[seIndex];
04103 vGains[seIndex]=gainCeiling;
04104 vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
04105
04106 MSG("LIPlexMaps",Msg::kInfo)
04107 <<"("<<pl<<":"<<st<<":"<<end<<")"
04108 <<" ** Capping very high gain ("<<oldGain
04109 <<") to be gainCeiling ("<<vGains[seIndex]<<")"<<endl
04110 <<" pixGain="<<pixelGain<<", pixNum="<<pixelNum
04111 <<", pmtGain="<<pmtGain<<", pmtNum="<<pmtNum<<endl;
04112 }
04113
04114
04115 vGainErrs[seIndex]=gainErrTooHighGain;
04116
04117
04118 hGainHighPmt->Fill(vGains[seIndex]);
04119 }
04120
04121
04122 CalADCtoPE calAdcToPe(seid.BuildPlnStripEndKey(),
04123 seid.GetEncoded(),vGains[seIndex],
04124 vGainErrs[seIndex],vSPEWidths[seIndex]);
04125 CalADCtoPEs calAdcToPes(agg,
04126 seid.BuildPlnStripEndKey(),vGains[seIndex],
04127 vGainErrs[seIndex],vSPEWidths[seIndex],vSPEWidthErrs[seIndex]);
04128
04129
04130 hGain->Fill(vGains[seIndex]);
04131 hGainErr->Fill(vGainErrs[seIndex]);
04132 hGainErrZoom->Fill(vGainErrs[seIndex]);
04133 hGainErrFract->Fill(vGainErrs[seIndex]/vGains[seIndex]);
04134 hSPEWidth->Fill(vSPEWidths[seIndex]);
04135
04136 if (crate>=FIRSTCRATE && crate<=LASTCRATE){
04137 hStripVsPlaneGain[crate]->Fill(pl,st,vGains[seIndex]);
04138 hStripVsPlaneGainErr[crate]->Fill(pl,st,vGainErrs[seIndex]);
04139 hStripVsPlaneSPEWidth[crate]->Fill(pl,st,vSPEWidths[seIndex]);
04140 }
04141
04142
04143 if(aggNo==-1) writer << calAdcToPe; else writers << calAdcToPes;
04144
04145
04146 gaindump << setw(4) << pl << " "
04147 << setw(3) << st << " "
04148 << setw(3) << end << " "
04149 << setw(4) << agg << " "
04150 << setw(6) << seid.BuildPlnStripEndKey() << " "
04151 << setw(9) << vGains[seIndex] << " "
04152 << setw(9) << vGainErrs[seIndex]
04153 << endl;
04154
04155
04156 totalCounter++; totalCounter2++;
04157
04158 if (MsgService::Instance()->
04159 IsActive("LIPlexMaps",Msg::kVerbose)){
04160 MSG("LIPlexMaps",Msg::kInfo)
04161 <<"("<<pl<<":"<<st<<":"<<end<<")"
04162 <<" "<<vGains[seIndex]<<" "
04163 <<vGainErrs[seIndex]<<" "<<vSPEWidths[seIndex]<<endl;
04164 }
04165 }
04166 }
04167 }
04168
04169
04170 gaindump.flush();
04171
04172
04173
04174 if(aggNo!=-1) {
04175 Int_t totalCounted2 = goodCounter2+pixCounter2+nnCounter2+pmtCounter2+
04176 detCounter2+gainHighCounter2;
04177 Int_t numBadStripends2 = totalCounted2-goodCounter2;
04178
04179 MSG("LIPlexMaps",Msg::kInfo)
04180 <<" AggNo= "<<setw(4)<<agg<<" Ntot= "<<setw(3)<<totalCounted2
04181 <<" Ngood= "<<setw(3)<<goodCounter2<<" Nbad= "<<setw(3)<<numBadStripends2
04182 <<" Npix= "<<setw(3)<<pixCounter2<<" Nnn= "<<setw(3)<<nnCounter2<<" Npmt= "<<setw(3)<<pmtCounter2<<" Ndet= "<<setw(3)<<detCounter2
04183 <<" Nhot= "<<setw(3)<<gainHighCounter2<<" Ncrazy= "<<setw(3)<<gainCappedCounter2<<endl;
04184
04185 MSG("LIPlexMaps",Msg::kInfo)
04186 <<"DbiWriters.IsOpen="<<writers.IsOpen()<<endl
04187 <<"DbiWriters.CanOuptpu="<<writers.CanOutput()<<endl;
04188
04189
04190 Bool_t badagg = false;
04191 Double_t badfrac = (Double_t)numBadStripends2 / (Double_t)totalCounted2;
04192
04193 if (badfrac > 0.3125) badagg = true;
04194
04195
04196 if (gainCappedCounter2 > 2) {
04197 MSG("LIPlexMaps", Msg::kInfo) << "Aggregate has too many crazies" << endl;
04198 badagg = true;
04199 }
04200
04201 if (writeToDb){
04202 if (badagg) {
04203 MSG("LIPlexMaps",Msg::kInfo) << "Aggregate is bad: Not Writing to database" << endl;
04204 } else {
04205 if (this->IsPermitted()) {
04206 MSG("LIPlexMaps",Msg::kInfo)
04207 <<"Writing to database..."<<endl;
04208
04209 writers.Close();
04210 MSG("LIPlexMaps",Msg::kInfo)
04211 <<"Finished writing to database"<<endl<<endl;
04212 }
04213 }
04214 }
04215 else {
04216 MSG("LIPlexMaps",Msg::kInfo)
04217 <<"Mode is set to NOT write to database"<<endl<<endl;
04218 }
04219 }
04220 }
04221
04222 MSG("LIPlexMaps",Msg::kInfo)
04223 <<endl
04224 <<"Corrected_Info(mean+-rms): GainAvDet(overall)= "<<hGainAvDet->GetMean()<<" +- "<<hGainAvDet->GetRMS()
04225 <<" Gain(<"<<gainTooHigh<<")= "<<hGain->GetMean()<<" +- "<<hGain->GetRMS()
04226 <<" GainErrZoom= "<<hGainErrZoom->GetMean()<<" +- "<<hGainErrZoom->GetRMS()
04227 <<endl;
04228
04229 MSG("LIPlexMaps",Msg::kInfo)
04230 <<endl
04231 <<" ** Values used in method: **"<<endl
04232 <<" NUMPLANES="<<NUMPLANES<<endl
04233 <<" NUMSTRIPS="<<NUMSTRIPS<<endl
04234 <<" NUMENDS="<<NUMENDS<<endl
04235 <<" NUMBOOKENDS="<<NUMBOOKENDS<<endl;
04236
04237 if (det==Detector::kNear) {
04238 MSG("LIPlexMaps",Msg::kInfo)
04239 << " Total number of strip ends=" << 11616 << endl;
04240 }
04241 else {
04242 MSG("LIPlexMaps",Msg::kInfo)
04243 <<" Total number of strip ends="
04244 <<(NUMPLANES*NUMSTRIPS*NUMENDS)-(NUMBOOKENDS*NUMSTRIPS*NUMENDS)
04245 <<endl;
04246 }
04247
04248 Int_t totalCounted = goodCounter+pixCounter+nnCounter+pmtCounter+
04249 detCounter+gainHighCounter;
04250 Int_t numBadStripends=totalCounted-goodCounter;
04251
04252 MSG("LIPlexMaps",Msg::kInfo)
04253 <<endl
04254 <<" ** Job Summary **"<<endl
04255 <<" Num good stripends= "<<goodCounter
04256 <<" ( "<<100.*goodCounter/totalCounted<<" %)"<<endl
04257 <<" Num bad stripends= "<<numBadStripends
04258 <<" ( "<<100.*numBadStripends/totalCounted<<" %)"<<endl
04259 <<" with average pixel value= "<<pixCounter
04260 <<" ( "<<100.*pixCounter/totalCounted<<" %) gain too high= "<<pixgainHighCounter<<" (capped= "<<pixgainCappedCounter<<" )"<<endl
04261 <<" with average NN value= "<<nnCounter
04262 <<" ( "<<100.*nnCounter/totalCounted<<" %) gain too high= "<<nngainHighCounter<<" (capped= "<<nngainCappedCounter<<" )"<<endl
04263 <<" with average PMT value= "<<pmtCounter
04264 <<" ( "<<100.*pmtCounter/totalCounted<<" %) gain too high= "<<pmtgainHighCounter<<" (capped= "<<pmtgainCappedCounter<<" )"<<endl
04265 <<" with average-detector-PMT value= "<<detCounter
04266 <<" ( "<<100.*detCounter/totalCounted<<" %) Equiv. num PMTs= "
04267 <<1.*detCounter/(NUMPIXELS*NUMPIXELSPOTS)<<" gain too high= "<<detgainHighCounter<<" (capped= "<<detgainCappedCounter<<" )"<<endl
04268 <<" with too high gain= "<<gainHighCounter
04269 <<" ( "<<100.*gainHighCounter/totalCounted<<" %) gain capped= "<<gainCappedCounter
04270 <<" ( "<<100.*gainCappedCounter/totalCounted<<" %)"<<endl
04271 <<" Sum of above= "<<totalCounted<<endl
04272 <<" Total num written to DB= "<<totalCounter<<endl;
04273
04274
04275 if(aggNo==-1) {
04276
04277 MSG("LIPlexMaps",Msg::kInfo)
04278 <<"DbiWriter.IsOpen=" << writer.IsOpen()<<endl
04279 <<"DbiWriter.CanOutput=" << writer.CanOutput()<<endl;
04280
04281 if (writeToDb){
04282 if (this->IsPermitted()){
04283 MSG("LIPlexMaps",Msg::kInfo)
04284 <<"Writing to database..."<<endl;
04285
04286 writer.Close();
04287 MSG("LIPlexMaps",Msg::kInfo)
04288 <<"Finished writing to database"<<endl;
04289 }
04290 }
04291 else {
04292 MSG("LIPlexMaps",Msg::kInfo)
04293 <<"Mode is set to NOT write to database"<<endl;
04294 }
04295
04296 }
04297
04298
04299
04300
04301 gStyle->SetOptStat(1111111);
04302
04303
04304 TCanvas *cGain=new TCanvas("cGain","PMT Gain",0,0,1000,600);
04305 cGain->SetFillColor(0);
04306 cGain->cd();
04307 hGain->Draw();
04308
04309
04310 TCanvas *cGainHighPmt=new TCanvas("cGainHighPmt","PMT Gain: HighPmts",
04311 0,0,1000,600);
04312 cGainHighPmt->SetFillColor(0);
04313 cGainHighPmt->cd();
04314 hGainHighPmt->Draw();
04315
04316
04317
04318 TCanvas *cGainCrazyHighPmt=new TCanvas("cGainCrazyHighPmt",
04319 "PMT Gain: CrazyHighPmts",
04320 0,0,1000,600);
04321 cGainCrazyHighPmt->SetFillColor(0);
04322 cGainCrazyHighPmt->cd();
04323 hGainCrazyHighPmt->Draw();
04324
04325
04326 TCanvas *cGainErr=new TCanvas("cGainErr","PMT GainErr",0,0,1000,600);
04327 cGainErr->SetFillColor(0);
04328 cGainErr->cd();
04329 hGainErr->Draw();
04330 cGainErr->SetLogy();
04331
04332
04333 TCanvas *cGainErrZoom=new TCanvas("cGainErrZoom","PMT GainErrZoom",
04334 0,0,1000,600);
04335 cGainErrZoom->SetFillColor(0);
04336 cGainErrZoom->cd();
04337 hGainErrZoom->Draw();
04338
04339
04340 TCanvas *cGainErrFract=new TCanvas("cGainErrFract","PMT GainErrFract",
04341 0,0,1000,600);
04342 cGainErrFract->SetFillColor(0);
04343 cGainErrFract->cd();
04344 hGainErrFract->Draw();
04345
04346
04347 TCanvas *cSPEWidth=new TCanvas("cSPEWidth","PMT SPEWidth",
04348 0,0,1000,600);
04349 cSPEWidth->SetFillColor(0);
04350 cSPEWidth->cd();
04351 hSPEWidth->Draw();
04352
04353
04354 TCanvas *cGainAvDet=new TCanvas("cGainAvDet",
04355 "Gains of Av. PMT in Detector",
04356 0,0,1000,600);
04357 cGainAvDet->SetFillColor(0);
04358 cGainAvDet->cd();
04359 hGainAvDet->Draw();
04360
04361
04362 TCanvas *cStripVsPlaneGain=new TCanvas
04363 ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);
04364 cStripVsPlaneGain->SetFillColor(0);
04365 cStripVsPlaneGain->cd();
04366 string sDbGains="DbGainsNew";
04367 sDbGains+=Detector::AsString(static_cast<Detector::
04368 Detector_t>(det));
04369 sDbGains+=".ps";
04370 cStripVsPlaneGain->Print((sDbGains+"[").c_str());
04371 gErrorIgnoreLevel=1;
04372
04373 gStyle->SetOptStat(0);
04374 for (Int_t i=0;i<NUMCRATES;i++){
04375 cStripVsPlaneGain->Clear();
04376 hStripVsPlaneGain[i]->Draw("colz");
04377 cStripVsPlaneGain->Print(sDbGains.c_str());
04378 }
04379
04380
04381 gStyle->SetOptStat(1111111);
04382 cGain->Print(sDbGains.c_str());
04383 cGainAvDet->Print(sDbGains.c_str());
04384 cGainHighPmt->Print(sDbGains.c_str());
04385 cGainCrazyHighPmt->Print(sDbGains.c_str());
04386
04387 cStripVsPlaneGain->Print((sDbGains+"]").c_str());
04388 gErrorIgnoreLevel=0;
04389
04390
04391 TCanvas *cStripVsPlaneGainErr=new TCanvas
04392 ("cStripVsPlaneGainErr","StripVsPlane: GainErr",0,0,1000,800);
04393 cStripVsPlaneGainErr->SetFillColor(0);
04394 cStripVsPlaneGainErr->cd();
04395 string sDbGainErrs="DbGainErrsNew";
04396 sDbGainErrs+=Detector::AsString(static_cast<Detector::
04397 Detector_t>(det));
04398 sDbGainErrs+=".ps";
04399 cStripVsPlaneGainErr->Print((sDbGainErrs+"[").c_str());
04400 gErrorIgnoreLevel=1;
04401
04402 gStyle->SetOptStat(0);
04403 for (Int_t i=0;i<NUMCRATES;i++){
04404 cStripVsPlaneGainErr->Clear();
04405 hStripVsPlaneGainErr[i]->Draw("colz");
04406 hStripVsPlaneGainErr[i]->SetMaximum(2.0*gainErrAvDet);
04407 cStripVsPlaneGainErr->Print(sDbGainErrs.c_str());
04408 }
04409
04410
04411 gStyle->SetOptStat(1111111);
04412 cGainErr->Print(sDbGainErrs.c_str());
04413 cGainErrZoom->Print(sDbGainErrs.c_str());
04414 cGainErrFract->Print(sDbGainErrs.c_str());
04415
04416 cStripVsPlaneGainErr->Print((sDbGainErrs+"]").c_str());
04417 gErrorIgnoreLevel=0;
04418
04420
04422 TCanvas *cStripVsPlaneSPEWidth=new TCanvas
04423 ("cStripVsPlaneSPEWidth","StripVsPlane: SPEWidth",0,0,1000,800);
04424 cStripVsPlaneSPEWidth->SetFillColor(0);
04425 cStripVsPlaneSPEWidth->cd();
04426 string sDbSPEWidths="DbSPEWidthsNew";
04427 sDbSPEWidths+=Detector::AsString(static_cast<Detector::
04428 Detector_t>(det));
04429 sDbSPEWidths+=".ps";
04430 cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"[").c_str());
04431 gErrorIgnoreLevel=1;
04432
04433 gStyle->SetOptStat(0);
04434 for (Int_t i=0;i<NUMCRATES;i++){
04435 cStripVsPlaneSPEWidth->Clear();
04436 hStripVsPlaneSPEWidth[i]->Draw("colz");
04437 cStripVsPlaneSPEWidth->Print(sDbSPEWidths.c_str());
04438 }
04439
04440
04441 gStyle->SetOptStat(1111111);
04442 cSPEWidth->Print(sDbSPEWidths.c_str());
04443
04444 cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"]").c_str());
04445 gErrorIgnoreLevel=0;
04446
04447
04448 gStyle->SetOptStat(1111111);
04449
04450 MSG("LIPlexMaps",Msg::kInfo)
04451 <<endl<<" ** Finished the MakeCalAdcToPe method... ** "<<endl;
04452 }
04453
04454
04455
04456
04457
04458 void LIPlexMaps::DumpCalStripToStrip(std::string sDataFileName,
04459 Detector::Detector_t det,
04460 SimFlag::ESimFlag simFlag,
04461 VldTimeStamp ts,Int_t task) const
04462 {
04463 MSG("LIPlexMaps",Msg::kInfo)
04464 <<endl<<" ** Running the DumpCalStripToStrip() method... **"<<endl;
04465
04466 DbiResultPtr<CalStripToStrip> dbiCalStripToStrip;
04467 VldContext vldCtx(det,simFlag,ts);
04468 UInt_t numRows=dbiCalStripToStrip.NewQuery(vldCtx,task);
04469
04470
04471 MSG("LIPlexMaps",Msg::kInfo)
04472 <<"Opening file "<<sDataFileName<<"..."<<endl;
04473 ofstream odataFile(sDataFileName.c_str());
04474
04475 MSG("LIPlexMaps",Msg::kInfo)
04476 <<"New DB query produced "<<numRows<<" rows"
04477 <<", using task="<<task<<endl
04478 <<"Looping over rows..."<<endl;
04479
04480 for(UInt_t i=0;i<numRows;i++) {
04481 const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
04482
04483 Int_t seid_enc=calStripToStrip->GetStripEndId().GetEncoded();
04484 Float_t resp=calStripToStrip->GetResponse();
04485 Float_t respErr=calStripToStrip->GetResponseErr();
04486
04487 odataFile<<seid_enc<<"\t"<<resp<<"\t"<<respErr<<endl;
04488 }
04489 MSG("LIPlexMaps",Msg::kInfo)
04490 <<"Output file completed"<<endl;
04491
04492 MSG("LIPlexMaps",Msg::kInfo)
04493 <<endl<<" ** Finished the DumpCalStripToStrip method... ** "<<endl;
04494 }
04495
04496
04497
04498 void LIPlexMaps::DumpCalStripAtten(std::string sDataFileName,
04499 Detector::Detector_t det,
04500 SimFlag::ESimFlag simFlag,
04501 VldTimeStamp ts,Int_t task)
04502 {
04503 MSG("LIPlexMaps",Msg::kInfo)
04504 <<endl<<" ** Running the DumpCalStripAtten() method... **"<<endl;
04505
04506
04507 this->SetDetector(static_cast<Int_t>(det));
04508
04509 const Int_t firstStripBin=FIRSTSTRIP-8;
04510 const Int_t lastStripBin=LASTSTRIP+9;
04511 const Int_t bins=lastStripBin-firstStripBin;
04512
04513 string s="Lambda1, East side";
04514 TH2F *hStripVsPlaneLambda1East=new TH2F(s.c_str(),s.c_str(),
04515 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04516 0,LASTSCINTPLANE+1,
04517 bins,firstStripBin,lastStripBin);
04518 hStripVsPlaneLambda1East->GetXaxis()->SetTitle("Plane");
04519 hStripVsPlaneLambda1East->GetXaxis()->CenterTitle();
04520 hStripVsPlaneLambda1East->GetYaxis()->SetTitle("Strip");
04521 hStripVsPlaneLambda1East->GetYaxis()->CenterTitle();
04522
04523 s="Lambda1, West side";
04524 TH2F *hStripVsPlaneLambda1West=new TH2F(s.c_str(),s.c_str(),
04525 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04526 0,LASTSCINTPLANE+1,
04527 bins,firstStripBin,lastStripBin);
04528 hStripVsPlaneLambda1West->GetXaxis()->SetTitle("Plane");
04529 hStripVsPlaneLambda1West->GetXaxis()->CenterTitle();
04530 hStripVsPlaneLambda1West->GetYaxis()->SetTitle("Strip");
04531 hStripVsPlaneLambda1West->GetYaxis()->CenterTitle();
04532
04533 s="Lambda2, East side";
04534 TH2F *hStripVsPlaneLambda2East=new TH2F(s.c_str(),s.c_str(),
04535 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04536 0,LASTSCINTPLANE+1,
04537 bins,firstStripBin,lastStripBin);
04538 hStripVsPlaneLambda2East->GetXaxis()->SetTitle("Plane");
04539 hStripVsPlaneLambda2East->GetXaxis()->CenterTitle();
04540 hStripVsPlaneLambda2East->GetYaxis()->SetTitle("Strip");
04541 hStripVsPlaneLambda2East->GetYaxis()->CenterTitle();
04542
04543 s="Lambda2, West side";
04544 TH2F *hStripVsPlaneLambda2West=new TH2F(s.c_str(),s.c_str(),
04545 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04546 0,LASTSCINTPLANE+1,
04547 bins,firstStripBin,lastStripBin);
04548 hStripVsPlaneLambda2West->GetXaxis()->SetTitle("Plane");
04549 hStripVsPlaneLambda2West->GetXaxis()->CenterTitle();
04550 hStripVsPlaneLambda2West->GetYaxis()->SetTitle("Strip");
04551 hStripVsPlaneLambda2West->GetYaxis()->CenterTitle();
04552
04553 s="Frac1, East side";
04554 TH2F *hStripVsPlaneFrac1East=new TH2F(s.c_str(),s.c_str(),
04555 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04556 0,LASTSCINTPLANE+1,
04557 bins,firstStripBin,lastStripBin);
04558 hStripVsPlaneFrac1East->GetXaxis()->SetTitle("Plane");
04559 hStripVsPlaneFrac1East->GetXaxis()->CenterTitle();
04560 hStripVsPlaneFrac1East->GetYaxis()->SetTitle("Strip");
04561 hStripVsPlaneFrac1East->GetYaxis()->CenterTitle();
04562
04563 s="Frac1, West side";
04564 TH2F *hStripVsPlaneFrac1West=new TH2F(s.c_str(),s.c_str(),
04565 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04566 0,LASTSCINTPLANE+1,
04567 bins,firstStripBin,lastStripBin);
04568 hStripVsPlaneFrac1West->GetXaxis()->SetTitle("Plane");
04569 hStripVsPlaneFrac1West->GetXaxis()->CenterTitle();
04570 hStripVsPlaneFrac1West->GetYaxis()->SetTitle("Strip");
04571 hStripVsPlaneFrac1West->GetYaxis()->CenterTitle();
04572
04573 s="Atten, East side";
04574 TH2F *hStripVsPlaneAttenEast=new TH2F(s.c_str(),s.c_str(),
04575 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04576 0,LASTSCINTPLANE+1,
04577 bins,firstStripBin,lastStripBin);
04578 hStripVsPlaneAttenEast->GetXaxis()->SetTitle("Plane");
04579 hStripVsPlaneAttenEast->GetXaxis()->CenterTitle();
04580 hStripVsPlaneAttenEast->GetYaxis()->SetTitle("Strip");
04581 hStripVsPlaneAttenEast->GetYaxis()->CenterTitle();
04582
04583 s="Atten, West side";
04584 TH2F *hStripVsPlaneAttenWest=new TH2F(s.c_str(),s.c_str(),
04585 LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04586 0,LASTSCINTPLANE+1,
04587 bins,firstStripBin,lastStripBin);
04588 hStripVsPlaneAttenWest->GetXaxis()->SetTitle("Plane");
04589 hStripVsPlaneAttenWest->GetXaxis()->CenterTitle();
04590 hStripVsPlaneAttenWest->GetYaxis()->SetTitle("Strip");
04591 hStripVsPlaneAttenWest->GetYaxis()->CenterTitle();
04592
04593 DbiResultPtr<CalStripAtten> dbiCalStripAtten;
04594 VldContext vldCtx(det,simFlag,ts);
04595 UInt_t numRows=dbiCalStripAtten.NewQuery(vldCtx,task);
04596
04597
04598 MSG("LIPlexMaps",Msg::kInfo)
04599 <<"Opening file "<<sDataFileName<<"..."<<endl;
04600 ofstream odataFile(sDataFileName.c_str());
04601
04602 MSG("LIPlexMaps",Msg::kInfo)
04603 <<"New DB query produced "<<numRows<<" rows"
04604 <<", using task="<<task<<endl
04605 <<"Looping over rows..."<<endl;
04606
04607 for(UInt_t i=0;i<numRows;i++) {
04608 const CalStripAtten* calStripAtten=dbiCalStripAtten.GetRow(i);
04609
04610
04611
04612
04613
04614
04615
04616
04617
04618
04619
04620
04621
04622
04623
04624
04625
04626
04627
04628 Int_t seid_enc=calStripAtten->GetStripEndId().GetEncoded();
04629 Float_t lambda1=calStripAtten->GetLambda1();
04630 Float_t lambda2=calStripAtten->GetLambda2();
04631 Float_t frac1=calStripAtten->GetFrac1();
04632 Float_t lambda1Err=calStripAtten->GetLambda1Err();
04633 Float_t lambda2Err=calStripAtten->GetLambda2Err();
04634 Float_t frac1Err=calStripAtten->GetFrac1Err();
04635
04636 MAXMSG("LIPlexMaps",Msg::kInfo,10)
04637 <<"seid_enc="<<seid_enc
04638 <<", GetSEIDkey="<<calStripAtten->GetSEIDkey()<<endl;
04639
04640 PlexStripEndId seid=calStripAtten->GetStripEndId();
04641 Int_t plane=seid.GetPlane();
04642 Int_t strip=seid.GetStrip();
04643 Int_t se=seid.GetEnd();
04644 Float_t x=1.5;
04645
04646
04647
04648
04649
04650
04651
04652 Float_t atten=frac1*exp(-x/lambda1)+(1-frac1)*exp(-x/lambda2);
04653
04654 if (se==StripEnd::kEast){
04655 hStripVsPlaneLambda1East->Fill(plane,strip,lambda1);
04656 hStripVsPlaneLambda2East->Fill(plane,strip,lambda2);
04657 hStripVsPlaneFrac1East->Fill(plane,strip,frac1);
04658 hStripVsPlaneAttenEast->Fill(plane,strip,atten);
04659 }
04660 else {
04661 hStripVsPlaneLambda1West->Fill(plane,strip,lambda1);
04662 hStripVsPlaneLambda2West->Fill(plane,strip,lambda2);
04663 hStripVsPlaneFrac1West->Fill(plane,strip,frac1);
04664 hStripVsPlaneAttenWest->Fill(plane,strip,atten);
04665 }
04666
04667 odataFile<<seid_enc
04668 <<"\t"<<lambda1
04669 <<"\t"<<lambda2
04670 <<"\t"<<frac1
04671 <<"\t"<<lambda1Err
04672 <<"\t"<<lambda2Err
04673 <<"\t"<<frac1Err
04674 <<endl;
04675 }
04676 MSG("LIPlexMaps",Msg::kInfo)
04677 <<"Output file completed"<<endl;
04678
04679 TCanvas *cStripVsPlaneLambda1=new TCanvas
04680 ("cStripVsPlaneLambda1","StripVsPlane: Mean",0,0,1100,800);
04681 cStripVsPlaneLambda1->SetFillColor(0);
04682 cStripVsPlaneLambda1->Divide(1,2);
04683 cStripVsPlaneLambda1->cd(1);
04684 hStripVsPlaneLambda1East->Draw("colz");
04685 cStripVsPlaneLambda1->cd(2);
04686 hStripVsPlaneLambda1West->Draw("colz");
04687
04688 TCanvas *cStripVsPlaneLambda2=new TCanvas
04689 ("cStripVsPlaneLambda2","StripVsPlane: Mean",0,0,1100,800);
04690 cStripVsPlaneLambda2->SetFillColor(0);
04691 cStripVsPlaneLambda2->Divide(1,2);
04692 cStripVsPlaneLambda2->cd(1);
04693 hStripVsPlaneLambda2East->Draw("colz");
04694 cStripVsPlaneLambda2->cd(2);
04695 hStripVsPlaneLambda2West->Draw("colz");
04696
04697 TCanvas *cStripVsPlaneFrac1=new TCanvas
04698 ("cStripVsPlaneFrac1","StripVsPlane: Mean",0,0,1100,800);
04699 cStripVsPlaneFrac1->SetFillColor(0);
04700 cStripVsPlaneFrac1->Divide(1,2);
04701 cStripVsPlaneFrac1->cd(1);
04702 hStripVsPlaneFrac1East->Draw("colz");
04703 cStripVsPlaneFrac1->cd(2);
04704 hStripVsPlaneFrac1West->Draw("colz");
04705
04706 TCanvas *cStripVsPlaneAtten=new TCanvas
04707 ("cStripVsPlaneAtten","StripVsPlane: Mean",0,0,1100,800);
04708 cStripVsPlaneAtten->SetFillColor(0);
04709 cStripVsPlaneAtten->Divide(1,2);
04710 cStripVsPlaneAtten->cd(1);
04711 hStripVsPlaneAttenEast->Draw("colz");
04712 cStripVsPlaneAtten->cd(2);
04713 hStripVsPlaneAttenWest->Draw("colz");
04714
04715 MSG("LIPlexMaps",Msg::kInfo)
04716 <<endl<<" ** Finished the DumpCalStripAtten method... ** "<<endl;
04717 }
04718
04719
04720
04721 void LIPlexMaps::MakeCalStripToStrip(std::string sDataFileName,
04722 Detector::Detector_t det,
04723 SimFlag::ESimFlag simFlag,
04724 VldTimeStamp vldStart,
04725 VldTimeStamp vldEnd,
04726 Int_t aggNo,
04727 Int_t task,
04728 VldTimeStamp creationDate,
04729 std::string dbName,
04730 std::string sLogComment,
04731 Bool_t writeToDb)
04732 {
04733 MSG("LIPlexMaps",Msg::kInfo)
04734 <<endl<<" ** Running the MakeCalStripToStrip() method... **"<<endl;
04735
04736 this->SetDetector(static_cast<Int_t>(det));
04737
04738
04739 MSG("LIPlexMaps",Msg::kInfo)
04740 <<"Opening file "<<sDataFileName<<"..."<<endl;
04741 ifstream dataFile(sDataFileName.c_str());
04742
04743 if (!dataFile){
04744 MSG("LIPlexMaps",Msg::kInfo)
04745 <<"Can't open file "<<sDataFileName<<endl
04746 <<"Exiting here..."<<endl;
04747 exit(1);
04748 }
04749
04750
04751 VldRange vr(det,simFlag,vldStart,vldEnd,
04752 "LISummary/LIPlexMaps::MakeCalStripToStrip");
04753 MSG("LIPlexMaps",Msg::kInfo)
04754 <<"Using Validity Range: "<<vr.AsString()<<endl;
04755
04756 MSG("LIPlexMaps",Msg::kInfo)
04757 <<"Log comment="<<sLogComment<<endl;
04758
04759
04760 DbiWriter<CalStripToStrip> writer(vr,aggNo,task,creationDate,dbName,
04761 sLogComment);
04762
04763 Int_t seid_enc=-1;
04764 Float_t resp=-1;
04765 Float_t respErr=-1;
04766 Float_t defaultResp=1;
04767 Float_t defaultRespErr=1;
04768
04769 Int_t counter=0;
04770
04771
04772 map<Int_t,myCalStripToStrip> inputCalSts;
04773
04774
04775
04776 for (Int_t pl=FIRSTSCINTPLANE;pl<=LASTSCINTPLANE;pl++){
04777 for (Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
04778
04779
04780 if (det==Detector::kNear && st>67 && (pl-1)%5!=0) continue;
04781
04782
04783 if (det==Detector::kNear && pl>120 && (pl-1)%5!=0) continue;
04784
04785
04786 if (det==Detector::kFar && pl==249) continue;
04787
04788 MAXMSG("LIPlexMaps",Msg::kInfo,10)
04789 <<"pl="<<pl<<", st="<<st<<endl;
04790
04791 PlexStripEndId seidE(det,pl,st,StripEnd::kEast);
04792 PlexStripEndId seidW(det,pl,st,StripEnd::kWest);
04793
04794
04795 if (det!=Detector::kNear){
04796 MAXMSG("LIPlexMaps",Msg::kInfo,1)
04797 <<endl<<"Detector is not ND thus creating East stripends..."
04798 <<endl;
04799 inputCalSts[seidE.GetEncoded()]=myCalStripToStrip
04800 (seidE.GetEncoded(),defaultResp,defaultRespErr);;
04801 }
04802
04803
04804 inputCalSts[seidW.GetEncoded()]=myCalStripToStrip
04805 (seidW.GetEncoded(),defaultResp,defaultRespErr);;
04806
04807 }
04808 }
04809
04810 MSG("LIPlexMaps",Msg::kInfo)
04811 <<"Map initialised with size="<<inputCalSts.size()<<endl;
04812
04813
04814 while(dataFile>>seid_enc>>resp>>respErr) {
04815
04816 MAXMSG("LIPlexMaps",Msg::kInfo,10)
04817 <<"Found line in file: seid_enc="<<seid_enc
04818 <<", resp="<<resp<<", respErr="<<respErr<<endl;
04819
04820
04821
04822
04823
04824 inputCalSts[seid_enc]=myCalStripToStrip(seid_enc,resp,respErr);;
04825
04826
04827
04828
04829 counter++;
04830 }
04831
04832 MSG("LIPlexMaps",Msg::kInfo)
04833 <<"Found "<<counter<<" rows in file: "<<sDataFileName
04834 <<", mapSize="<<inputCalSts.size()<<endl;
04835
04836
04837 typedef map<Int_t,myCalStripToStrip>::const_iterator stsIt;
04838 for (stsIt it=inputCalSts.begin();it!=inputCalSts.end();it++){
04839 const myCalStripToStrip& c=it->second;
04840 CalStripToStrip calStripToStrip(c.seid_enc,c.response,c.responseErr);
04841 MAXMSG("LIPlexMaps",Msg::kInfo,10)
04842 <<"Writing to database: seidEnc="<<c.seid_enc
04843 <<", resp="<<c.response<<", respErr="<<c.responseErr<<endl;
04844 writer<<calStripToStrip;
04845 }
04846
04847 MSG("LIPlexMaps",Msg::kInfo)
04848 <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
04849 <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
04850
04851 if (writeToDb){
04852 if (this->IsPermitted()){
04853 MSG("LIPlexMaps",Msg::kInfo)
04854 <<"Writing to database..."<<endl;
04855
04856 writer.Close();
04857 MSG("LIPlexMaps",Msg::kInfo)
04858 <<"Finished writing to database"<<endl;
04859 }
04860 }
04861 else {
04862 MSG("LIPlexMaps",Msg::kInfo)
04863 <<"Mode is set to NOT write to database"<<endl;
04864 }
04865
04866 MSG("LIPlexMaps",Msg::kInfo)
04867 <<endl<<" ** Finished the MakeCalStripToStrip method... ** "<<endl;
04868 }
04869
04870
04871
04872 void LIPlexMaps::MakeCalStripAtten(std::string sDataFileName,
04873 Detector::Detector_t det,
04874 SimFlag::ESimFlag simFlag,
04875 VldTimeStamp vldStart,
04876 VldTimeStamp vldEnd,
04877 Int_t aggNo,
04878 Int_t task,
04879 VldTimeStamp creationDate,
04880 std::string dbName,
04881 std::string sLogComment,
04882 Int_t iFileFormat,
04883 Bool_t writeToDb)
04884 {
04885 MSG("LIPlexMaps",Msg::kInfo)
04886 <<endl<<" ** Running the MakeCalStripAtten() method... **"<<endl;
04887
04888 this->SetDetector(static_cast<Int_t>(det));
04889
04890
04891 MSG("LIPlexMaps",Msg::kInfo)
04892 <<"Opening file "<<sDataFileName<<"..."<<endl;
04893 ifstream dataFile(sDataFileName.c_str());
04894
04895 if (!dataFile){
04896 MSG("LIPlexMaps",Msg::kInfo)
04897 <<"Can't open file "<<sDataFileName<<endl
04898 <<"Exiting here..."<<endl;
04899 exit(1);
04900 }
04901
04902
04903 VldRange vr(det,simFlag,vldStart,vldEnd,
04904 "LISummary/LIPlexMaps::MakeCalStripAtten");
04905 MSG("LIPlexMaps",Msg::kInfo)
04906 <<"Using Validity Range: "<<vr.AsString()<<endl;
04907
04908 MSG("LIPlexMaps",Msg::kInfo)
04909 <<"Log comment="<<sLogComment<<endl;
04910
04911
04912 DbiWriter<CalStripAtten> writer(vr,aggNo,task,creationDate,dbName,
04913 sLogComment);
04914 Int_t counter=0;
04915
04916 if (iFileFormat==0) {
04917 MAXMSG("LIPlexMaps",Msg::kInfo,100)
04918 <<"Assuming fileFormat=0 (=Leon/Jiajie's format)"<<endl;
04919 Int_t TotalLines=12000;
04920 Char_t buffer[248], moduleid[11];
04921 Int_t plane,strip,module_strip,ndf;
04922 Double_t chi2,shortAmp,shortAmp_err,shortAtt,shortAtt_err;
04923 Double_t longAmp,longAmp_err,longAtt,longAtt_err;
04924
04925 dataFile.getline(buffer,248);
04926
04927 for(Int_t i=0; i<TotalLines; i++) {
04928 if(!dataFile.good()) break;
04929 dataFile >> moduleid >> module_strip >> plane >> strip >> shortAmp
04930 >> shortAmp_err >> shortAtt >> shortAtt_err >> longAmp
04931 >> longAmp_err >> longAtt >> longAtt_err >> chi2 >> ndf;
04932
04933 Double_t frac1 = shortAmp/(shortAmp+longAmp);
04934 Double_t frac1_err = 0;
04935 Double_t SAerr_2 = pow(shortAmp_err,2);
04936 Double_t LAerr_2 = pow(longAmp_err,2);
04937 Double_t SLA = shortAmp + longAmp;
04938
04939 if(shortAmp>0)
04940 frac1_err = frac1 * sqrt(SAerr_2/(2*shortAmp)+
04941 (SAerr_2+LAerr_2)/pow(SLA,2));
04942 PlexStripEndId seid(Detector::kNear,plane,strip,StripEnd::kWest);
04943
04944 MAXMSG("LIPlexMaps",Msg::kInfo,100)
04945 <<"Found line in file: seid_enc="<<seid.AsString()
04946 <<", shortAtt="<<shortAtt/100.<< ", longAtt=" <<longAtt/100.
04947 <<", frac1="<<frac1 << endl;
04948
04949 CalStripAtten calStripAtten(seid,shortAtt/100.,longAtt/100.,
04950 frac1,shortAtt_err/100,longAtt_err/100.,
04951 frac1_err);
04952 writer << calStripAtten;
04953 counter++;
04954 }
04955 dataFile.getline(buffer,248);
04956 }
04957 else if (iFileFormat==1) {
04958 MAXMSG("LIPlexMaps",Msg::kInfo,100)
04959 <<"Assuming fileFormat=1 (=DumpCalStripAtten)"<<endl;
04960
04961 Int_t seid_enc=-1;
04962 Float_t lambda1=-1;
04963 Float_t lambda2=-1;
04964 Float_t frac1=-1;
04965 Float_t lambda1Err=-1;
04966 Float_t lambda2Err=-1;
04967 Float_t frac1Err=-1;
04968
04969
04970 while(dataFile
04971 >>seid_enc
04972 >>lambda1
04973 >>lambda2
04974 >>frac1
04975 >>lambda1Err
04976 >>lambda2Err
04977 >>frac1Err) {
04978
04979 MAXMSG("LIPlexMaps",Msg::kInfo,10)
04980 <<"Found line in file: seid_enc="<<seid_enc
04981 <<", lambda1="<<lambda1
04982 <<", lambda2="<<lambda2
04983 <<", frac1="<<frac1
04984 <<endl;
04985
04986
04987 CalStripAtten calStripAtten(seid_enc,lambda1,lambda2,frac1,
04988 lambda1Err,lambda2Err,frac1Err);
04989
04990
04991 writer<<calStripAtten;
04992
04993 counter++;
04994 }
04995 }
04996 else {
04997 MSG("LIPlexMaps",Msg::kError)
04998 <<"Input file format not recognised = "<<iFileFormat
04999 <<", will exit here..."<<endl;
05000 exit(1);
05001 }
05002 dataFile.close();
05003
05004 MSG("LIPlexMaps",Msg::kInfo)
05005 <<"Found "<<counter<<" rows in file: "<<sDataFileName<<endl;
05006
05007 MSG("LIPlexMaps",Msg::kInfo)
05008 <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
05009 <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
05010
05011 if (writeToDb){
05012 if (this->IsPermitted()){
05013 MSG("LIPlexMaps",Msg::kInfo)
05014 <<"Writing to database..."<<endl;
05015
05016 writer.Close();
05017 MSG("LIPlexMaps",Msg::kInfo)
05018 <<"Finished writing to database"<<endl;
05019 }
05020 }
05021 else {
05022 MSG("LIPlexMaps",Msg::kInfo)
05023 <<"Mode is set to NOT write to database"<<endl;
05024 }
05025
05026 MSG("LIPlexMaps",Msg::kInfo)
05027 <<endl<<" ** Finished the MakeCalStripAtten method... ** "<<endl;
05028 }
05029
05030
05031
05032 void LIPlexMaps::MakeCalMIPCalibration(Float_t scale,
05033 Detector::Detector_t det,
05034 SimFlag::ESimFlag simFlag,
05035 VldTimeStamp vldStart,
05036 VldTimeStamp vldEnd,
05037 Int_t aggNo,
05038 Int_t task,
05039 VldTimeStamp creationDate,
05040 std::string dbName,
05041 std::string sLogComment,
05042 Bool_t writeToDb)
05043 {
05044 MSG("LIPlexMaps",Msg::kInfo)
05045 <<endl<<" ** Running the MakeCalMIPCalibration() method... **"<<endl;
05046
05047
05048
05049 VldRange vr(det,simFlag,vldStart,vldEnd,
05050 "LISummary/LIPlexMaps::MakeCalMIPCalibration");
05051 MSG("LIPlexMaps",Msg::kInfo)
05052 <<"Using Validity Range: "<<vr.AsString()<<endl;
05053
05054 MSG("LIPlexMaps",Msg::kInfo)
05055 <<"Other settings used:"<<endl
05056 <<"aggNo="<<aggNo<<endl
05057 <<"task="<<task<<endl
05058 <<"creationDate="<<creationDate<<endl
05059 <<"dbName="<<dbName<<endl
05060 <<"sLogComment="<<sLogComment<<endl
05061 <<"writeToDb="<<writeToDb<<endl;
05062
05063
05064 DbiWriter<CalMIPCalibration> writer(vr,aggNo,task,creationDate,dbName,
05065 sLogComment);
05066
05067
05068
05069 Int_t seidkey=0;
05070 Int_t stripendid=0;
05071
05072
05073 CalMIPCalibration calMIPCalibration(seidkey,stripendid,scale);
05074 MSG("LIPlexMaps",Msg::kInfo)
05075 <<"Writing point with:"<<endl
05076 <<" seidkey="<<seidkey<<endl
05077 <<" stripendid="<<stripendid<<endl
05078 <<" scale="<<scale<<endl;
05079
05080
05081 writer<<calMIPCalibration;
05082
05083 MSG("LIPlexMaps",Msg::kInfo)
05084 <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
05085 <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
05086
05087 if (writeToDb){
05088 if (this->IsPermitted()){
05089 MSG("LIPlexMaps",Msg::kInfo)
05090 <<"Writing to database..."<<endl;
05091
05092 writer.Close();
05093 MSG("LIPlexMaps",Msg::kInfo)
05094 <<"Finished writing to database"<<endl;
05095 }
05096 }
05097 else {
05098 MSG("LIPlexMaps",Msg::kInfo)
05099 <<"Mode is set to NOT write to database"<<endl;
05100 }
05101
05102 MSG("LIPlexMaps",Msg::kInfo)
05103 <<endl<<" ** Finished the MakeCalMIPCalibration method... ** "<<endl;
05104 }
05105
05106
05107
05108 void LIPlexMaps::MakePlexStripEndToLed(Bool_t writeToDb)
05109 {
05110 MSG("LIPlexMaps",Msg::kInfo)
05111 <<endl<<" ** Running the MakePlexStripEndToLed method... ** "
05112 <<endl;
05113
05114
05115 Detector::Detector_t det=Detector::kCalDet;
05116
05117 Int_t* planeMax=new Int_t[NUMCRATES];
05118 Int_t* planeMin=new Int_t[NUMCRATES];
05119 fLookup.SetPbPlanes(planeMin,planeMax,det);
05120
05121 const Int_t firstStripBin=FIRSTSTRIP-8;
05122 const Int_t lastStripBin=LASTSTRIP+9;
05123 const Int_t bins=lastStripBin-firstStripBin;
05124
05125 string sConstantBit="";
05126
05127 MSG("LIAnalysis",Msg::kInfo)
05128 <<"sConstantBit="<<sConstantBit<<endl;
05129
05130 TH2F **hStripVsPlaneLed=0;
05131 hStripVsPlaneLed= new TH2F*[NUMCRATES];
05132 for (Int_t i=0;i<NUMCRATES;i++){
05133 string sPb=Form("%d",i);
05134 fS="Led (Crate "+sPb+")";
05135 hStripVsPlaneLed[i]=new TH2F(fS.c_str(),fS.c_str(),
05136 planeMax[i]-planeMin[i],
05137 planeMin[i],planeMax[i],
05138 bins,firstStripBin,lastStripBin);
05139 hStripVsPlaneLed[i]->GetXaxis()->SetTitle("Plane");
05140 hStripVsPlaneLed[i]->GetXaxis()->CenterTitle();
05141 hStripVsPlaneLed[i]->GetYaxis()->SetTitle("Strip");
05142 hStripVsPlaneLed[i]->GetYaxis()->CenterTitle();
05143 hStripVsPlaneLed[i]->SetFillColor(0);
05144
05145 }
05146
05147
05148 VldTimeStamp tsStart=VldTimeStamp(2003,3,1,12,0,0);
05149 MSG("LIPlexMaps",Msg::kInfo)
05150 <<"Vld start time: ";
05151 tsStart.Print();
05152 MSG("LIPlexMaps",Msg::kInfo)
05153 <<endl;
05154 VldTimeStamp tsEnd=VldTimeStamp(2010,1,1,12,0,0);
05155 MSG("LIPlexMaps",Msg::kInfo)
05156 <<"Vld end time: ";
05157 tsEnd.Print();
05158 MSG("LIPlexMaps",Msg::kInfo)
05159 <<endl;
05160
05161
05162 VldRange vldRng(det,SimFlag::kData,tsStart,tsEnd,
05163 "MakePlexStripEndToLed");
05164 MSG("LIPlexMaps",Msg::kInfo)
05165 <<"Validity range: ";
05166 vldRng.Print();
05167 MSG("LIPlexMaps",Msg::kInfo)
05168 <<endl;
05169
05170 VldTimeStamp tsNow;
05171 VldContext vldNow(det,SimFlag::kData,tsNow);
05172 PlexHandle plexHandle(vldNow);
05173
05174
05175
05176
05178
05180
05181
05182
05183
05184
05185
05186
05187
05188
05189
05190
05191
05192
05193
05194
05195
05196 for(Int_t pb=0;pb<NUMPULSERBOXES;pb++){
05197 for(Int_t led=4;led<=6;led++){
05198
05199 MSG("LIPlexMaps",Msg::kInfo)
05200 <<"Pulser box="<<pb<<", led="<<led<<endl;
05201
05202
05203 PlexLedId ledId(det,pb,led);
05204
05205
05206 int aggNo=0x7ff & ledId.GetEncoded();
05207 MSG("LIPlexMaps",Msg::kInfo)
05208 <<"aggNo="<<aggNo<<", encoded="<<ledId.GetEncoded()
05209 <<", det="<<(ledId.GetEncoded()>>11)<<endl;
05210
05211
05212 string logComment="Updated to reflect the state of the detector";
05213
05214 UInt_t dbNo=1;
05215
05216
05217 DbiWriter<PlexStripEndToLed> writer(vldRng,aggNo,0,tsNow,dbNo,
05218 logComment);
05219
05220 MSG("LIPlexMaps",Msg::kInfo)
05221 <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl;
05222
05223
05224
05225
05226
05227 for(Int_t plane=FIRSTPLANE;plane<=LASTPLANE;plane++){
05228 for(Int_t strip=FIRSTSTRIP;strip<=LASTSTRIP;strip++){
05229 for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
05230
05231 StripEnd::StripEnd_t stripEndType = StripEnd::kUnknown;
05232 if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
05233 else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
05234
05235 PlexStripEndId stripEndId(det,plane,strip,stripEndType);
05236
05237
05238 Int_t crate=plexHandle.GetRawChannelId(stripEndId).
05239 GetCrate();
05240
05242
05243 if (plane==0 && end==1 && (crate==1 || crate==2) &&
05244 det==Detector::kCalDet){
05245 crate=0;
05246 MSG("LIPlexMaps",Msg::kInfo)
05247 <<"Doing plane 0 caldet hack"<<endl;
05248 }
05249
05250
05251
05252 PlexStripEndToLed stripEndToLed
05253 (det,plane,strip,stripEndType,pb,
05254 fLookup.Strip2Led(strip,plane,det,crate));
05255
05256
05257
05258 MSG("LIPlexMaps",Msg::kDebug)
05259 <<"("<<plane<<";"<<strip<<";"<<stripEndType<<")"
05260 <<" ("<<pb<<":"<<led<<")"
05261 <<", strip2led="
05262 <<fLookup.Strip2Led(strip,plane,det,crate)<<")"
05263 <<", crate="<<crate
05264 <<", aggNo="<<stripEndToLed.GetAggregateNo()
05265 <<endl;
05266
05267 ReadoutType::Readout_t rt=plexHandle.GetReadoutType
05268 (plexHandle.GetRawChannelId(stripEndToLed.
05269 GetPlexStripEndId()));
05270
05271 if (rt!=ReadoutType::kScintStrip){
05272 MSG("LIPlexMaps",Msg::kInfo)
05273 <<"rt="<<ReadoutType::AsString(rt)<<endl;
05274 continue;
05275 }
05276
05277
05278 if(stripEndToLed.GetPlexStripEndId().GetPlane()!=plane ||
05279 stripEndToLed.GetPlexStripEndId().IsSteel() ||
05280 stripEndToLed.GetPlexStripEndId().IsVetoShield() ||
05281 !stripEndToLed.GetPlexStripEndId().IsValid()) {
05282
05283 MSG("LIPlexMaps",Msg::kInfo)
05284 <<"Stripend to led was bad: IsSteel="
05285 <<stripEndToLed.GetPlexStripEndId().IsSteel()
05286 <<", IsVetoShield="
05287 <<stripEndToLed.GetPlexStripEndId().IsVetoShield()
05288 <<", IsValid="
05289 <<stripEndToLed.GetPlexStripEndId().IsValid()
05290 <<", GetPlane="
05291 <<stripEndToLed.GetPlexStripEndId().GetPlane()
05292 <<", plane="<<plane
05293 <<endl;
05294 continue;
05295 }
05296
05297
05298
05299 if(stripEndToLed.GetPlexLedId().GetEncoded()==
05300 ledId.GetEncoded()) {
05301
05302
05303
05304
05305
05306 if(crate!=pb && det==Detector::kFar) continue;
05307
05308 MSG("LIPlexMaps",Msg::kInfo)
05309 <<stripEndToLed.GetAggregateNo()<<" "
05310 <<stripEndToLed.GetPlexStripEndId().GetPlane()<<" "
05311 <<stripEndToLed.GetPlexStripEndId().GetStrip()<<" "
05312 <<stripEndToLed.GetPlexStripEndId().GetEnd()<<" "
05313 <<stripEndToLed.GetPlexLedId().GetPulserBox()<<" "
05314 <<stripEndToLed.GetPlexLedId().GetLedInBox()<<endl;
05315
05316
05317 hStripVsPlaneLed[end-1]->Fill
05318 (stripEndToLed.GetPlexStripEndId().GetPlane(),
05319 stripEndToLed.GetPlexStripEndId().GetStrip(),
05320 stripEndToLed.GetPlexLedId().GetLedInBox());
05321
05322 writer<<stripEndToLed;
05323
05324 }
05325 else{
05326 MSG("LIPlexMaps",Msg::kDebug)
05327 <<"("<<plane<<";"<<strip<<";"<<stripEndType<<")"
05328 <<" ("<<pb<<":"<<led<<")"
05329 <<" These don't match: stripend to led encoded="
05330 <<stripEndToLed.GetPlexLedId().GetEncoded()
05331 <<", ledid encoded="<<ledId.GetEncoded()
05332 <<endl;
05333 }
05334 }
05335 }
05336 }
05337
05338 MSG("LIPlexMaps",Msg::kInfo)
05339 <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
05340 <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
05341
05342 if (writeToDb){
05343 if (this->IsPermitted()){
05344 MSG("LIPlexMaps",Msg::kInfo)
05345 <<"Writing to database..."<<endl;
05346
05347 writer.Close();
05348 MSG("LIPlexMaps",Msg::kInfo)
05349 <<"Finished writing to database"<<endl;
05350 }
05351 }
05352 else {
05353 MSG("LIPlexMaps",Msg::kInfo)
05354 <<"Mode is set to NOT write to database"<<endl;
05355 }
05356
05357 }
05358 }
05359
05360
05361 gStyle->SetOptStat(0);
05362
05363 TCanvas *cStripVsPlaneLed=new TCanvas
05364 ("cStripVsPlaneLed","StripVsPlane: Led",0,0,1000,800);
05365 cStripVsPlaneLed->SetFillColor(0);
05366 cStripVsPlaneLed->Divide(1,2);
05367 cStripVsPlaneLed->cd(1);
05368 hStripVsPlaneLed[0]->Draw("textcolz");
05369 cStripVsPlaneLed->cd(2);
05370 hStripVsPlaneLed[1]->Draw("textcolz");
05371
05372 MSG("LIPlexMaps",Msg::kInfo)
05373 <<endl<<" ** Finished the MakePlexStripEndToLed method... ** "
05374 <<endl;
05375 }
05376
05377
05378
05379 void LIPlexMaps::ReadDbCalStripToStrip(Int_t det,VldTimeStamp ts,
05380 Int_t task)
05381 {
05382 MSG("LIPlexMaps",Msg::kInfo)
05383 <<endl<<" ** Running the ReadDbCalStripToStrip() method... ** "<<endl;
05384
05385 this->SetDetector(det);
05386
05387 const Int_t firstStripBin=FIRSTSTRIP-2;
05388 const Int_t lastStripBin=LASTSTRIP+2;
05389 const Int_t stripBins=lastStripBin-firstStripBin;
05390
05391 const Int_t firstPlaneBin=FIRSTPLANE-2;;
05392 const Int_t lastPlaneBin=LASTPLANE+2;
05393 const Int_t planeBins=lastPlaneBin-firstPlaneBin;
05394
05395 TH2F* hStVsPlResp1=new TH2F("hStVsPlResp1","hStVsPlResp1",
05396 planeBins,firstPlaneBin,lastPlaneBin,
05397 stripBins,firstStripBin,lastStripBin);
05398 hStVsPlResp1->SetTitle("Detector Response (East side)");
05399 hStVsPlResp1->GetXaxis()->SetTitle("Plane");
05400 hStVsPlResp1->GetXaxis()->CenterTitle();
05401 hStVsPlResp1->GetYaxis()->SetTitle("Strip");
05402 hStVsPlResp1->GetYaxis()->CenterTitle();
05403 hStVsPlResp1->SetFillColor(0);
05404
05405 TH2F* hStVsPlRespErr1=new TH2F("hStVsPlRespErr1","hStVsPlRespErr1",
05406 planeBins,firstPlaneBin,lastPlaneBin,
05407 stripBins,firstStripBin,lastStripBin);
05408 hStVsPlRespErr1->SetTitle("Detector Response Error (East side)");
05409 hStVsPlRespErr1->GetXaxis()->SetTitle("Plane");
05410 hStVsPlRespErr1->GetXaxis()->CenterTitle();
05411 hStVsPlRespErr1->GetYaxis()->SetTitle("Strip");
05412 hStVsPlRespErr1->GetYaxis()->CenterTitle();
05413 hStVsPlRespErr1->SetFillColor(0);
05414
05415 TH2F* hStVsPlResp2=new TH2F("hStVsPlResp2","hStVsPlResp2",
05416 planeBins,firstPlaneBin,lastPlaneBin,
05417 stripBins,firstStripBin,lastStripBin);
05418 hStVsPlResp2->SetTitle("Detector Response (West side)");
05419 hStVsPlResp2->GetXaxis()->SetTitle("Plane");
05420 hStVsPlResp2->GetXaxis()->CenterTitle();
05421 hStVsPlResp2->GetYaxis()->SetTitle("Strip");
05422 hStVsPlResp2->GetYaxis()->CenterTitle();
05423 hStVsPlResp2->SetFillColor(0);
05424
05425 TH2F* hStVsPlRespErr2=new TH2F("hStVsPlRespErr2","hStVsPlRespErr2",
05426 planeBins,firstPlaneBin,lastPlaneBin,
05427 stripBins,firstStripBin,lastStripBin);
05428 hStVsPlRespErr2->SetTitle("Detector Response Error (West side)");
05429 hStVsPlRespErr2->GetXaxis()->SetTitle("Plane");
05430 hStVsPlRespErr2->GetXaxis()->CenterTitle();
05431 hStVsPlRespErr2->GetYaxis()->SetTitle("Strip");
05432 hStVsPlRespErr2->GetYaxis()->CenterTitle();
05433 hStVsPlRespErr2->SetFillColor(0);
05434
05435 TH1F *hResponse=new TH1F("hResponse","hResponse",300,-1,10);
05436 hResponse->GetXaxis()->SetTitle("Response of Stripends");
05437 hResponse->GetXaxis()->CenterTitle();
05438 hResponse->GetYaxis()->SetTitle("");
05439 hResponse->GetYaxis()->CenterTitle();
05440 hResponse->SetLineColor(2);
05441 hResponse->SetFillStyle(3015);
05442 hResponse->SetFillColor(2);
05443 hResponse->SetLineWidth(3);
05444
05445
05446 TH1F *hRespE=new TH1F("hRespE","hRespE",500,-1,10);
05447 hRespE->GetXaxis()->SetTitle("Response of East Stripends");
05448 hRespE->GetXaxis()->CenterTitle();
05449 hRespE->GetYaxis()->SetTitle("");
05450 hRespE->GetYaxis()->CenterTitle();
05451 hRespE->SetLineColor(4);
05452 hRespE->SetFillStyle(3015);
05453 hRespE->SetFillColor(4);
05454 hRespE->SetLineWidth(3);
05455
05456
05457 TH1F *hRespW=new TH1F("hRespW","hRespW",500,-1,10);
05458 hRespW->GetXaxis()->SetTitle("Response of West Stripends");
05459 hRespW->GetXaxis()->CenterTitle();
05460 hRespW->GetYaxis()->SetTitle("");
05461 hRespW->GetYaxis()->CenterTitle();
05462 hRespW->SetLineColor(2);
05463 hRespW->SetFillStyle(3015);
05464 hRespW->SetFillColor(2);
05465 hRespW->SetLineWidth(3);
05466
05467
05468 TH1F *hResponseErr=new TH1F("hResponseErr","hResponseErr",
05469 200,-0.02,0.2);
05470 hResponseErr->GetXaxis()->SetTitle("ResponseErr of Stripends");
05471 hResponseErr->GetXaxis()->CenterTitle();
05472 hResponseErr->GetYaxis()->SetTitle("");
05473 hResponseErr->GetYaxis()->CenterTitle();
05474 hResponseErr->SetLineColor(3);
05475 hResponseErr->SetFillStyle(3015);
05476 hResponseErr->SetFillColor(3);
05477 hResponseErr->SetLineWidth(3);
05478
05479
05480 TProfile* pSigCorVsPlane=new TProfile
05481 ("pSigCorVsPlane","pSigCorVsPlane",
05482 planeBins,firstPlaneBin,lastPlaneBin);
05483 pSigCorVsPlane->GetXaxis()->SetTitle("Plane");
05484 pSigCorVsPlane->GetXaxis()->CenterTitle();
05485 pSigCorVsPlane->GetYaxis()->SetTitle("SigCor");
05486 pSigCorVsPlane->GetYaxis()->CenterTitle();
05487 pSigCorVsPlane->SetLineColor(2);
05488 pSigCorVsPlane->SetLineWidth(3);
05489
05490
05491 TProfile* pSigCorVsPlaneCoarse=new TProfile
05492 ("pSigCorVsPlaneCoarse","pSigCorVsPlaneCoarse",6,0,60);
05493 pSigCorVsPlaneCoarse->GetXaxis()->SetTitle("Plane");
05494 pSigCorVsPlaneCoarse->GetXaxis()->CenterTitle();
05495 pSigCorVsPlaneCoarse->GetYaxis()->SetTitle("SigCor");
05496 pSigCorVsPlaneCoarse->GetYaxis()->CenterTitle();
05497 pSigCorVsPlaneCoarse->SetLineColor(2);
05498 pSigCorVsPlaneCoarse->SetLineWidth(3);
05499
05500
05501 TProfile* pSigCorVsPlane1=new TProfile
05502 ("pSigCorVsPlane1","pSigCorVsPlane1",
05503 planeBins,firstPlaneBin,lastPlaneBin);
05504 pSigCorVsPlane1->GetXaxis()->SetTitle("Plane");
05505 pSigCorVsPlane1->GetXaxis()->CenterTitle();
05506 pSigCorVsPlane1->GetYaxis()->SetTitle("SigCor");
05507 pSigCorVsPlane1->GetYaxis()->CenterTitle();
05508 pSigCorVsPlane1->SetLineColor(2);
05509 pSigCorVsPlane1->SetLineWidth(3);
05510
05511
05512 TProfile* pSigCorVsPlane2=new TProfile
05513 ("pSigCorVsPlane2","pSigCorVsPlane2",
05514 planeBins,firstPlaneBin,lastPlaneBin);
05515 pSigCorVsPlane2->GetXaxis()->SetTitle("Plane");
05516 pSigCorVsPlane2->GetXaxis()->CenterTitle();
05517 pSigCorVsPlane2->GetYaxis()->SetTitle("SigCor");
05518 pSigCorVsPlane2->GetYaxis()->CenterTitle();
05519 pSigCorVsPlane2->SetLineColor(2);
05520 pSigCorVsPlane2->SetLineWidth(3);
05521
05522
05523 TProfile* pSigCorVsStrip=new TProfile
05524 ("pSigCorVsStrip","pSigCorVsStrip",
05525 stripBins,firstStripBin,lastStripBin);
05526 pSigCorVsStrip->GetXaxis()->SetTitle("Strip");
05527 pSigCorVsStrip->GetXaxis()->CenterTitle();
05528 pSigCorVsStrip->GetYaxis()->SetTitle("SigCor");
05529 pSigCorVsStrip->GetYaxis()->CenterTitle();
05530 pSigCorVsStrip->SetLineColor(4);
05531 pSigCorVsStrip->SetLineWidth(3);
05532
05533
05534 TProfile* pSigCorVsStripCoarse=new TProfile
05535 ("pSigCorVsStripCoarse","pSigCorVsStripCoarse",12,0,24);
05536 pSigCorVsStripCoarse->GetXaxis()->SetTitle("Strip");
05537 pSigCorVsStripCoarse->GetXaxis()->CenterTitle();
05538 pSigCorVsStripCoarse->GetYaxis()->SetTitle("SigCor");
05539 pSigCorVsStripCoarse->GetYaxis()->CenterTitle();
05540 pSigCorVsStripCoarse->SetLineColor(2);
05541 pSigCorVsStripCoarse->SetLineWidth(3);
05542
05543
05544 TProfile* pSigCorVsStrip1=new TProfile
05545 ("pSigCorVsStrip1","pSigCorVsStrip1",
05546 stripBins,firstStripBin,lastStripBin);
05547 pSigCorVsStrip1->GetXaxis()->SetTitle("Strip");
05548 pSigCorVsStrip1->GetXaxis()->CenterTitle();
05549 pSigCorVsStrip1->GetYaxis()->SetTitle("SigCor");
05550 pSigCorVsStrip1->GetYaxis()->CenterTitle();
05551 pSigCorVsStrip1->SetLineColor(4);
05552 pSigCorVsStrip1->SetLineWidth(3);
05553
05554
05555 TProfile* pSigCorVsStrip2=new TProfile
05556 ("pSigCorVsStrip2","pSigCorVsStrip2",
05557 stripBins,firstStripBin,lastStripBin);
05558 pSigCorVsStrip2->GetXaxis()->SetTitle("Strip");
05559 pSigCorVsStrip2->GetXaxis()->CenterTitle();
05560 pSigCorVsStrip2->GetYaxis()->SetTitle("SigCor");
05561 pSigCorVsStrip2->GetYaxis()->CenterTitle();
05562 pSigCorVsStrip2->SetLineColor(4);
05563 pSigCorVsStrip2->SetLineWidth(3);
05564
05565
05566 Float_t avRespSpect=0;
05567 Float_t avCorSpect=0;
05568 Float_t avRespSpectCounter=0;
05569 Float_t avRespCalor=0;
05570 Float_t avCorCalor=0;
05571 Float_t avRespCalorCounter=0;
05572
05573 map<Int_t,Float_t> mStripResp1;
05574 map<Int_t,Float_t> mStripResp2;
05575
05576 VldContext vldCtx(static_cast<Detector::Detector_t>(det),
05577 SimFlag::kData,ts);
05578 vldCtx.Print();
05579
05580 DbiResultPtr<CalStripToStrip> dbiCalStripToStrip;
05581 UInt_t numRows=dbiCalStripToStrip.NewQuery(vldCtx,task);
05582
05583 MSG("LIPlexMaps",Msg::kInfo)
05584 <<"New DB query produced "<<numRows<<" rows"
05585 <<", using task="<<task<<endl
05586 <<"Looping over rows..."<<endl;
05587
05588
05589 for(UInt_t i=0;i<numRows;i++) {
05590 const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
05591
05592 Float_t response=calStripToStrip->GetResponse();
05593 Float_t responseErr=calStripToStrip->GetResponseErr();
05594 PlexStripEndId seid=calStripToStrip->GetStripEndId();
05595 Int_t plane=seid.GetPlane();
05596 Int_t strip=seid.GetStrip();
05597 Int_t se=seid.GetEnd();
05598
05599 if (plane==2){
05600 if (se==1){
05601 mStripResp1[strip]=response;
05602 }
05603 else if (se==2){
05604 mStripResp2[strip]=response;
05605 }
05606 }
05607
05608 pSigCorVsStrip->Fill(strip,response);
05609 pSigCorVsPlane->Fill(plane,response);
05610
05611 if (se==StripEnd::kEast){
05612 hRespE->Fill(response);
05613 pSigCorVsStrip1->Fill(strip,response);
05614 pSigCorVsPlane1->Fill(plane,response);
05615 hStVsPlResp1->Fill(plane,strip,response);
05616 hStVsPlRespErr1->Fill(plane,strip,responseErr);
05617 }
05618 else if (se==StripEnd::kWest){
05619 hRespW->Fill(response);
05620 pSigCorVsStrip2->Fill(strip,response);
05621 pSigCorVsPlane2->Fill(plane,response);
05622 hStVsPlResp2->Fill(plane,strip,response);
05623 hStVsPlRespErr2->Fill(plane,strip,responseErr);
05624
05625 if (plane>120) {
05626 avRespSpect+=response;
05627 avCorSpect+=1./response;
05628 avRespSpectCounter++;
05629 }
05630 else {
05631 avRespCalor+=response;
05632 avCorCalor+=1./response;
05633 avRespCalorCounter++;
05634 }
05635 }
05636 else cout<<"Ahhhhh"<<endl;
05637
05638 hResponse->Fill(response);
05639 hResponseErr->Fill(responseErr);
05640 }
05641
05642 MSG("LIPlexMaps",Msg::kInfo)
05643 <<"Av response="<<hResponse->GetMean()
05644 <<" (N="<<hResponse->GetEntries()<<")"<<endl
05645 <<" East av response="<<hRespE->GetMean()
05646 <<" (N="<<hRespE->GetEntries()<<")"<<endl
05647 <<" West av response="<<hRespW->GetMean()
05648 <<" (N="<<hRespW->GetEntries()<<")"<<endl;
05649
05650
05651 avRespSpect/=avRespSpectCounter;
05652 avCorSpect/=avRespSpectCounter;
05653 avRespCalor/=avRespCalorCounter;
05654 avCorCalor/=avRespCalorCounter;
05655
05656 MSG("LIPlexMaps",Msg::kInfo)
05657 <<endl
05658 <<"Calorimeter av response ="<<avRespCalor
05659 <<"(N="<<avRespCalorCounter<<")"
05660 <<endl
05661 <<"Calorimeter av correction ="<<avCorCalor
05662 <<endl
05663 <<"Spectrometer av response ="<<avRespSpect
05664 <<"(N="<<avRespSpectCounter<<")"
05665 <<endl
05666 <<"Spectrometer av correction="<<avCorSpect
05667 <<endl;
05668
05669 for (UInt_t i=0;i<mStripResp2.size();i++){
05670 cout<<"Strip="<<i<<", response 1="<<mStripResp1[i]
05671 <<" response 2="<<mStripResp2[i]<<endl;
05672 }
05673
05674 TCanvas *cResponse=new TCanvas
05675 ("cResponse","cResponse",0,0,1000,1000);
05676 cResponse->SetFillColor(0);
05677 cResponse->Divide(2,1);
05678 cResponse->cd(1);
05679 hResponse->Draw();
05680 cResponse->cd(2);
05681 hResponseErr->Draw();
05682
05683 TCanvas *cPlSt=new TCanvas
05684 ("cPlSt","cPlSt",0,0,1000,1000);
05685 cPlSt->SetFillColor(0);
05686 cPlSt->Divide(1,2);
05687 cPlSt->cd(1);
05688 pSigCorVsPlane->Draw();
05689 cPlSt->cd(2);
05690 pSigCorVsStrip->Draw();
05691
05692 TCanvas *cPlSt1_2=new TCanvas
05693 ("cPlSt1_2","cPlSt1_2",0,0,1000,1000);
05694 cPlSt1_2->SetFillColor(0);
05695 cPlSt1_2->Divide(2,2);
05696 cPlSt1_2->cd(1);
05697 pSigCorVsPlane1->Draw();
05698 cPlSt1_2->cd(2);
05699 pSigCorVsPlane2->Draw();
05700 cPlSt1_2->cd(3);
05701 pSigCorVsStrip1->Draw();
05702 cPlSt1_2->cd(4);
05703 pSigCorVsStrip2->Draw();
05704
05705 TCanvas *cStVsPlResp=new TCanvas
05706 ("cStVsPlResp","cStVsPlResp",0,0,1000,1000);
05707 cStVsPlResp->SetFillColor(0);
05708 cStVsPlResp->Divide(1,2);
05709 cStVsPlResp->cd(1);
05710 hStVsPlResp1->Draw("colz");
05711 cStVsPlResp->cd(2);
05712 hStVsPlResp2->Draw("colz");
05713
05714 TCanvas *cStVsPlRespErr=new TCanvas
05715 ("cStVsPlRespErr","cStVsPlRespErr",0,0,1000,1000);
05716 cStVsPlRespErr->SetFillColor(0);
05717 cStVsPlRespErr->Divide(1,2);
05718 cStVsPlRespErr->cd(1);
05719 hStVsPlRespErr1->SetMaximum(0.12);
05720 hStVsPlRespErr2->SetMaximum(0.12);
05721 hStVsPlRespErr1->Draw("colz");
05722 cStVsPlRespErr->cd(2);
05723 hStVsPlRespErr2->Draw("colz");
05724
05725 cout<<"Printing histos..."<<endl;
05726 cResponse->Print("stripToStrip.ps[");
05727 cResponse->Print("stripToStrip.ps");
05728 cStVsPlResp->Print("stripToStrip.ps");
05729 cStVsPlRespErr->Print("stripToStrip.ps");
05730 cPlSt->Print("stripToStrip.ps");
05731 cPlSt1_2->Print("stripToStrip.ps");
05732 cResponse->Print("stripToStrip.ps]");
05733 cout<<"Finished printing histos"<<endl;
05734
05735 MSG("LIPlexMaps",Msg::kInfo)
05736 <<endl<<" ** Finished the ReadDbCalStripToStrip() method... **"<<endl;
05737 }
05738
05739
05740
05741 void LIPlexMaps::ReadDbCalStripAtten(Int_t det,VldTimeStamp ts, Int_t task) {
05742 MSG("LIPlexMaps",Msg::kInfo)
05743 <<endl<<" ** Running the ReadDbCalStripToStrip() method... ** "<<endl;
05744
05745 this->SetDetector(det);
05746
05747 TH1F *hShortAmp = new TH1F("hShortAmp","Short Attenuation fraction",200,0,1);
05748 hShortAmp->GetXaxis()->SetTitle("Short Attenuation fraction");
05749 hShortAmp->GetXaxis()->CenterTitle();
05750 hShortAmp->GetYaxis()->SetTitle("");
05751 hShortAmp->GetYaxis()->CenterTitle();
05752 hShortAmp->SetLineColor(2);
05753 hShortAmp->SetFillStyle(3015);
05754 hShortAmp->SetFillColor(2);
05755 hShortAmp->SetLineWidth(3);
05756
05757
05758 TH2F *hShortAmpDet = new TH2F("hShortAmpDet","Short Attenuation fraction",282,0,282,96,0,96);
05759 hShortAmpDet->GetXaxis()->SetTitle("Plane NO.");
05760 hShortAmpDet->GetXaxis()->CenterTitle();
05761 hShortAmpDet->GetYaxis()->SetTitle("Strip NO.");
05762 hShortAmpDet->GetYaxis()->CenterTitle();
05763
05764 TH1F *hLongAmp = new TH1F("hLongAmp","Long Attenuation fraction",200,0,1);
05765 hLongAmp->GetXaxis()->SetTitle("Long Attenuation fraction");
05766 hLongAmp->GetXaxis()->CenterTitle();
05767 hLongAmp->GetYaxis()->SetTitle("");
05768 hLongAmp->GetYaxis()->CenterTitle();
05769 hLongAmp->SetLineColor(4);
05770 hLongAmp->SetFillStyle(3015);
05771 hLongAmp->SetFillColor(4);
05772 hLongAmp->SetLineWidth(3);
05773
05774
05775 TH2F *hLongAmpDet = new TH2F("hLongAmpDet","Long Attenuation fraction",282,0,282,96,0,96);
05776 hLongAmpDet->GetXaxis()->SetTitle("Plane NO.");
05777 hLongAmpDet->GetXaxis()->CenterTitle();
05778 hLongAmpDet->GetYaxis()->SetTitle("Strip NO.");
05779 hLongAmpDet->GetYaxis()->CenterTitle();
05780
05781 TH1F *hShortLength = new TH1F("hShortLength","Short Attenuation Length",200,0,5.);
05782 hShortLength->GetXaxis()->SetTitle("Short Attenuation Length (m)");
05783 hShortLength->GetXaxis()->CenterTitle();
05784 hShortLength->GetYaxis()->SetTitle("");
05785 hShortLength->GetYaxis()->CenterTitle();
05786 hShortLength->SetLineColor(2);
05787 hShortLength->SetFillStyle(3015);
05788 hShortLength->SetFillColor(2);
05789 hShortLength->SetLineWidth(3);
05790
05791
05792 TH2F *hShortLenDet = new TH2F("hShortLenDet","Short Attenuation Length",282,0,282,96,0,96);
05793 hShortLenDet->GetXaxis()->SetTitle("Plane NO.");
05794 hShortLenDet->GetXaxis()->CenterTitle();
05795 hShortLenDet->GetYaxis()->SetTitle("Strip NO.");
05796 hShortLenDet->GetYaxis()->CenterTitle();
05797
05798 TH1F *hLongLength = new TH1F("hLongLength","Long Attenuation Length",200,0,50);
05799 hLongLength->GetXaxis()->SetTitle("Long Attenuation Length (m)");
05800 hLongLength->GetXaxis()->CenterTitle();
05801 hLongLength->GetYaxis()->SetTitle("");
05802 hLongLength->GetYaxis()->CenterTitle();
05803 hLongLength->SetLineColor(4);
05804 hLongLength->SetFillStyle(3015);
05805 hLongLength->SetFillColor(4);
05806 hLongLength->SetLineWidth(3);
05807
05808
05809 TH2F *hLongLenDet = new TH2F("hLongLenDet","Long Attenuation Length",282,0,282,96,0,96);
05810 hLongLenDet->GetXaxis()->SetTitle("Plane NO.");
05811 hLongLenDet->GetXaxis()->CenterTitle();
05812 hLongLenDet->GetYaxis()->SetTitle("Strip NO.");
05813 hLongLenDet->GetYaxis()->CenterTitle();
05814
05815 VldContext vldCtx(static_cast<Detector::Detector_t>(det),SimFlag::kData,ts);
05816 vldCtx.Print();
05817
05818 DbiResultPtr<CalStripAtten> dbiCalStripAtten;
05819 UInt_t numRows = dbiCalStripAtten.NewQuery(vldCtx,task);
05820
05821 MSG("LIPlexMaps",Msg::kInfo)
05822 <<"New DB query produced "<<numRows<<" rows"
05823 <<", using task="<<task<<endl
05824 <<"Looping over rows..."<<endl;
05825
05826
05827
05828
05829
05830
05831
05832
05833
05834
05835
05836
05837
05838
05839
05840
05841
05842
05843
05844
05845
05846
05847
05848
05849
05850
05851
05852
05853
05854
05855
05856
05857
05858
05859
05860
05861
05862
05863
05864 for(UInt_t i=0;i<numRows;i++) {
05865 const CalStripAtten* calStripAtten=dbiCalStripAtten.GetRow(i);
05866 Float_t Lambda1 = calStripAtten->GetLambda1();
05867 Float_t Lambda2 = calStripAtten->GetLambda2();
05868 Float_t frac1 = calStripAtten->GetFrac1();
05869
05870
05871
05872 PlexStripEndId seid = calStripAtten->GetStripEndId();
05873 Int_t plane = seid.GetPlane();
05874 Int_t strip = seid.GetStrip();
05875
05876
05877 hShortAmp->Fill(frac1);
05878 hLongAmp->Fill(1-frac1);
05879 hShortLength->Fill(Lambda1);
05880 hLongLength->Fill(Lambda2);
05881 hShortAmpDet->Fill(plane,strip,frac1);
05882 hLongAmpDet->Fill(plane,strip,1-frac1);
05883 hShortLenDet->Fill(plane,strip,Lambda1);
05884 hLongLenDet->Fill(plane,strip,Lambda2);
05885 }
05886
05887 TCanvas *cAtten = new TCanvas("cAtten","Attenuation Parameters",0,0,800,1000);
05888 cAtten->SetFillColor(0);
05889 cAtten->Divide(2,2);
05890 cAtten->cd(1);
05891 hShortAmp->Draw();
05892 cAtten->cd(2);
05893 hLongAmp->Draw();
05894 cAtten->cd(3);
05895 hShortLength->Draw();
05896 cAtten->cd(4);
05897 hLongLength->Draw();
05898
05899 TCanvas *cDet = new TCanvas("cDet","Attenuation Parameters for All the Strips",0,0,800,1000);
05900 cDet->SetFillColor(0);
05901 cDet->Divide(2,2);
05902 cDet->cd(1);
05903 hShortAmpDet->Draw("colz");
05904 cDet->cd(2);
05905 hLongAmpDet->Draw("colz");
05906 cDet->cd(3);
05907 hShortLenDet->Draw("colz");
05908 cDet->cd(4);
05909 hLongLenDet->Draw("colz");
05910
05911 cDet->Print("stripAtten.ps[");
05912 cDet->Print("stripAtten.ps");
05913 cAtten->Print("stripAtten.ps");
05914 cDet->Print("stripAtten.ps]");
05915
05916 MSG("LIPlexMaps",Msg::kInfo)
05917 <<endl<<" ** Finished the ReadDbCalStripAtten() method... ** "<<endl;
05918 }
05919
05920
05921
05922 void LIPlexMaps::CompareStripToStrip(Int_t det,VldTimeStamp ts,
05923 Int_t taskA,Int_t taskB)
05924 {
05925 MSG("LIPlexMaps",Msg::kInfo)
05926 <<endl<<" ** Running the CompareStripToStrip() method... ** "<<endl;
05927
05928 this->SetDetector(det);
05929
05930 const Int_t firstStripBin=FIRSTSTRIP-2;
05931 const Int_t lastStripBin=LASTSTRIP+2;
05932 const Int_t stripBins=lastStripBin-firstStripBin;
05933
05934 const Int_t firstPlaneBin=FIRSTPLANE-2;;
05935 const Int_t lastPlaneBin=LASTPLANE+2;
05936 const Int_t planeBins=lastPlaneBin-firstPlaneBin;
05937
05938
05939 TH1F *hResponse=new TH1F("hResponse","hResponse",300,-1,10);
05940 hResponse->GetXaxis()->SetTitle("Response of Stripends");
05941 hResponse->GetXaxis()->CenterTitle();
05942 hResponse->GetYaxis()->SetTitle("");
05943 hResponse->GetYaxis()->CenterTitle();
05944 hResponse->SetLineColor(2);
05945 hResponse->SetFillStyle(3015);
05946 hResponse->SetFillColor(2);
05947 hResponse->SetLineWidth(3);
05948
05949
05950 TH1F *hResponseErr=new TH1F("hResponseErr","hResponseErr",
05951 200,-0.02,0.2);
05952 hResponseErr->GetXaxis()->SetTitle("ResponseErr of Stripends");
05953 hResponseErr->GetXaxis()->CenterTitle();
05954 hResponseErr->GetYaxis()->SetTitle("");
05955 hResponseErr->GetYaxis()->CenterTitle();
05956 hResponseErr->SetLineColor(3);
05957 hResponseErr->SetFillStyle(3015);
05958 hResponseErr->SetFillColor(3);
05959 hResponseErr->SetLineWidth(3);
05960
05961
05962 TProfile* pRatioVsPlane=new TProfile
05963 ("pRatioVsPlane","pRatioVsPlane",
05964 planeBins,firstPlaneBin,lastPlaneBin);
05965 pRatioVsPlane->GetXaxis()->SetTitle("Plane");
05966 pRatioVsPlane->GetXaxis()->CenterTitle();
05967 pRatioVsPlane->GetYaxis()->SetTitle("Ratio");
05968 pRatioVsPlane->GetYaxis()->CenterTitle();
05969 pRatioVsPlane->SetLineColor(2);
05970 pRatioVsPlane->SetLineWidth(3);
05971
05972
05973 TProfile* pRatioVsPlaneCoarse=new TProfile
05974 ("pRatioVsPlaneCoarse","pRatioVsPlaneCoarse",6,0,60);
05975 pRatioVsPlaneCoarse->SetTitle("Ratio of S2S Cal. Const. (Cosmic/PS)");
05976 pRatioVsPlaneCoarse->GetXaxis()->SetTitle("Plane");
05977 pRatioVsPlaneCoarse->GetXaxis()->CenterTitle();
05978 pRatioVsPlaneCoarse->GetYaxis()->SetTitle("Ratio");
05979 pRatioVsPlaneCoarse->GetYaxis()->CenterTitle();
05980 pRatioVsPlaneCoarse->SetLineColor(2);
05981 pRatioVsPlaneCoarse->SetLineWidth(3);
05982
05983
05984 TProfile* pRatioVsPlane1=new TProfile
05985 ("pRatioVsPlane1","pRatioVsPlane1",
05986 planeBins,firstPlaneBin,lastPlaneBin);
05987 pRatioVsPlane1->GetXaxis()->SetTitle("Plane");
05988 pRatioVsPlane1->GetXaxis()->CenterTitle();
05989 pRatioVsPlane1->GetYaxis()->SetTitle("Ratio");
05990 pRatioVsPlane1->GetYaxis()->CenterTitle();
05991 pRatioVsPlane1->SetLineColor(2);
05992 pRatioVsPlane1->SetLineWidth(3);
05993
05994
05995 TProfile* pRatioVsPlane2=new TProfile
05996 ("pRatioVsPlane2","pRatioVsPlane2",
05997 planeBins,firstPlaneBin,lastPlaneBin);
05998 pRatioVsPlane2->GetXaxis()->SetTitle("Plane");
05999 pRatioVsPlane2->GetXaxis()->CenterTitle();
06000 pRatioVsPlane2->GetYaxis()->SetTitle("Ratio");
06001 pRatioVsPlane2->GetYaxis()->CenterTitle();
06002 pRatioVsPlane2->SetLineColor(2);
06003 pRatioVsPlane2->SetLineWidth(3);
06004
06005
06006 Int_t coarseStBins=(lastStripBin-firstStripBin)/2;
06007 TProfile* pRatioVsStripO1=new TProfile
06008 ("pRatioVsStripO1","pRatioVsStripO1",
06009 coarseStBins,firstStripBin,lastStripBin);
06010 pRatioVsStripO1->GetXaxis()->SetTitle("Strip");
06011 pRatioVsStripO1->GetXaxis()->CenterTitle();
06012 pRatioVsStripO1->GetYaxis()->SetTitle("Ratio");
06013 pRatioVsStripO1->GetYaxis()->CenterTitle();
06014 pRatioVsStripO1->SetLineColor(2);
06015 pRatioVsStripO1->SetLineWidth(3);
06016
06017
06018 TProfile* pRatioVsStripO2=new TProfile
06019 ("pRatioVsStripO2","pRatioVsStripO2",
06020 coarseStBins,firstStripBin,lastStripBin);
06021 pRatioVsStripO2->GetXaxis()->SetTitle("Strip");
06022 pRatioVsStripO2->GetXaxis()->CenterTitle();
06023 pRatioVsStripO2->GetYaxis()->SetTitle("Ratio");
06024 pRatioVsStripO2->GetYaxis()->CenterTitle();
06025 pRatioVsStripO2->SetLineColor(2);
06026 pRatioVsStripO2->SetLineWidth(3);
06027
06028
06029 TProfile* pRatioVsStripE1=new TProfile
06030 ("pRatioVsStripE1","pRatioVsStripE1",
06031 coarseStBins,firstStripBin,lastStripBin);
06032 pRatioVsStripE1->GetXaxis()->SetTitle("Strip");
06033 pRatioVsStripE1->GetXaxis()->CenterTitle();
06034 pRatioVsStripE1->GetYaxis()->SetTitle("Ratio");
06035 pRatioVsStripE1->GetYaxis()->CenterTitle();
06036 pRatioVsStripE1->SetLineColor(2);
06037 pRatioVsStripE1->SetLineWidth(3);
06038
06039
06040 TProfile* pRatioVsStripE2=new TProfile
06041 ("pRatioVsStripE2","pRatioVsStripE2",
06042 coarseStBins,firstStripBin,lastStripBin);
06043 pRatioVsStripE2->GetXaxis()->SetTitle("Strip");
06044 pRatioVsStripE2->GetXaxis()->CenterTitle();
06045 pRatioVsStripE2->GetYaxis()->SetTitle("Ratio");
06046 pRatioVsStripE2->GetYaxis()->CenterTitle();
06047 pRatioVsStripE2->SetLineColor(2);
06048 pRatioVsStripE2->SetLineWidth(3);
06049
06050
06051 TProfile* pRatioVsStrip=new TProfile
06052 ("pRatioVsStrip","pRatioVsStrip",
06053 stripBins,firstStripBin,lastStripBin);
06054 pRatioVsStrip->GetXaxis()->SetTitle("Strip");
06055 pRatioVsStrip->GetXaxis()->CenterTitle();
06056 pRatioVsStrip->GetYaxis()->SetTitle("Ratio");
06057 pRatioVsStrip->GetYaxis()->CenterTitle();
06058 pRatioVsStrip->SetLineColor(4);
06059 pRatioVsStrip->SetLineWidth(3);
06060
06061
06062 TProfile* pRatioVsStripCoarse=new TProfile
06063 ("pRatioVsStripCoarse","pRatioVsStripCoarse",12,0,24);
06064 pRatioVsStripCoarse->SetTitle("Ratio of S2S Cal. Const. (Cosmic/PS)");
06065 pRatioVsStripCoarse->GetXaxis()->SetTitle("Strip");
06066 pRatioVsStripCoarse->GetXaxis()->CenterTitle();
06067 pRatioVsStripCoarse->GetYaxis()->SetTitle("Ratio");
06068 pRatioVsStripCoarse->GetYaxis()->CenterTitle();
06069 pRatioVsStripCoarse->SetLineColor(2);
06070 pRatioVsStripCoarse->SetLineWidth(3);
06071
06072
06073 TProfile* pRatioVsStripCoarseFront=new TProfile
06074 ("pRatioVsStripCoarseFront","pRatioVsStripCoarseFront",12,0,24);
06075 pRatioVsStripCoarseFront->
06076 SetTitle("Ratio of S2S Cal. Const. Det. Front (Cosmic/PS)");
06077 pRatioVsStripCoarseFront->GetXaxis()->SetTitle("Strip");
06078 pRatioVsStripCoarseFront->GetXaxis()->CenterTitle();
06079 pRatioVsStripCoarseFront->GetYaxis()->SetTitle("Ratio");
06080 pRatioVsStripCoarseFront->GetYaxis()->CenterTitle();
06081 pRatioVsStripCoarseFront->SetLineColor(2);
06082 pRatioVsStripCoarseFront->SetLineWidth(3);
06083
06084
06085 TProfile* pRatioVsStripCoarseBack=new TProfile
06086 ("pRatioVsStripCoarseBack","pRatioVsStripCoarseBack",12,0,24);
06087 pRatioVsStripCoarseBack->
06088 SetTitle("Ratio of S2S Cal. Const. Det. Back (Cosmic/PS)");
06089 pRatioVsStripCoarseBack->GetXaxis()->SetTitle("Strip");
06090 pRatioVsStripCoarseBack->GetXaxis()->CenterTitle();
06091 pRatioVsStripCoarseBack->GetYaxis()->SetTitle("Ratio");
06092 pRatioVsStripCoarseBack->GetYaxis()->CenterTitle();
06093 pRatioVsStripCoarseBack->SetLineColor(2);
06094 pRatioVsStripCoarseBack->SetLineWidth(3);
06095
06096
06097 TProfile* pRatioVsStrip1=new TProfile
06098 ("pRatioVsStrip1","pRatioVsStrip1",
06099 stripBins,firstStripBin,lastStripBin);
06100 pRatioVsStrip1->GetXaxis()->SetTitle("Strip");
06101 pRatioVsStrip1->GetXaxis()->CenterTitle();
06102 pRatioVsStrip1->GetYaxis()->SetTitle("Ratio");
06103 pRatioVsStrip1->GetYaxis()->CenterTitle();
06104 pRatioVsStrip1->SetLineColor(4);
06105 pRatioVsStrip1->SetLineWidth(3);
06106
06107
06108 TProfile* pRatioVsStrip2=new TProfile
06109 ("pRatioVsStrip2","pRatioVsStrip2",
06110 stripBins,firstStripBin,lastStripBin);
06111 pRatioVsStrip2->GetXaxis()->SetTitle("Strip");
06112 pRatioVsStrip2->GetXaxis()->CenterTitle();
06113 pRatioVsStrip2->GetYaxis()->SetTitle("Ratio");
06114 pRatioVsStrip2->GetYaxis()->CenterTitle();
06115 pRatioVsStrip2->SetLineColor(4);
06116 pRatioVsStrip2->SetLineWidth(3);
06117
06118
06119 TProfile2D* pStVsPlRatio1=new TProfile2D
06120 ("pStVsPlRatio1","pStVsPlRatio1",
06121 planeBins,firstPlaneBin,lastPlaneBin,
06122 stripBins,firstStripBin,lastStripBin);
06123 pStVsPlRatio1->GetXaxis()->SetTitle("Plane");
06124 pStVsPlRatio1->GetXaxis()->CenterTitle();
06125 pStVsPlRatio1->GetYaxis()->SetTitle("Strip");
06126 pStVsPlRatio1->GetYaxis()->CenterTitle();
06127
06128
06129 TProfile2D* pStVsPlRatio2=new TProfile2D
06130 ("pStVsPlRatio2","pStVsPlRatio2",
06131 planeBins,firstPlaneBin,lastPlaneBin,
06132 stripBins,firstStripBin,lastStripBin);
06133 pStVsPlRatio2->GetXaxis()->SetTitle("Plane");
06134 pStVsPlRatio2->GetXaxis()->CenterTitle();
06135 pStVsPlRatio2->GetYaxis()->SetTitle("Strip");
06136 pStVsPlRatio2->GetYaxis()->CenterTitle();
06137
06138
06139 map<PlexStripEndId,Float_t> sigCorA;
06140 map<PlexStripEndId,Float_t> sigCorB;
06141
06142 VldContext vldCtx(static_cast<Detector::Detector_t>(det),
06143 SimFlag::kData,ts);
06144 vldCtx.Print();
06145 UInt_t year=0;
06146 ts.GetDate(true,0,&year);
06147
06148 DbiResultPtr<CalStripToStrip> dbiCalStripToStrip;
06149
06150
06151 UInt_t numRows=dbiCalStripToStrip.NewQuery(vldCtx,taskA);
06152
06153 MSG("LIPlexMaps",Msg::kInfo)
06154 <<"New DB query produced "<<numRows<<" rows"
06155 <<", using task="<<taskA<<endl
06156 <<"Looping over rows..."<<endl;
06157
06158 for(UInt_t i=0;i<numRows;i++) {
06159 const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
06160
06161 Float_t response=calStripToStrip->GetResponse();
06162 PlexStripEndId seid=calStripToStrip->GetStripEndId();
06163 sigCorA[seid]=response;
06164 }
06165
06166
06167 numRows=dbiCalStripToStrip.NewQuery(vldCtx,taskB);
06168
06169 MSG("LIPlexMaps",Msg::kInfo)
06170 <<"New DB query produced "<<numRows<<" rows"
06171 <<", using task="<<taskB<<endl
06172 <<"Looping over rows..."<<endl;
06173
06174 for(UInt_t i=0;i<numRows;i++) {
06175 const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
06176
06177 Float_t response=calStripToStrip->GetResponse();
06178 PlexStripEndId seid=calStripToStrip->GetStripEndId();
06179 sigCorB[seid]=response;
06180 }
06181
06182 MSG("LIPlexMaps",Msg::kInfo)
06183 <<"Found maps, sigCorA size="<<sigCorA.size()
06184 <<", sigCorB size="<<sigCorB.size()<<endl;
06185
06186 for (map<PlexStripEndId,Float_t>::iterator iterA=sigCorA.begin();
06187 iterA!=sigCorA.end();++iterA){
06188
06189 map<PlexStripEndId,Float_t>::iterator iterB=
06190 sigCorB.find(iterA->first);
06191
06192 if (iterB==sigCorB.end()){
06193 MSG("LIPlexMaps",Msg::kWarning)
06194 <<"Ahhhhhh, missing iterB"<<endl;
06195 continue;
06196 }
06197
06198 Int_t planeA=iterA->first.GetPlane();
06199 Int_t stripA=iterA->first.GetStrip();
06200 Int_t seA=iterA->first.GetEnd();
06201 Int_t planeB=iterB->first.GetPlane();
06202 Int_t stripB=iterB->first.GetStrip();
06203 Int_t seB=iterB->first.GetEnd();
06204
06205 MSG("LIPlexMaps",Msg::kDebug)
06206 <<"A: st="<<stripA<<", pl="<<planeA<<", se="<<seA<<endl;
06207 MSG("LIPlexMaps",Msg::kDebug)
06208 <<"B: st="<<stripB<<", pl="<<planeB<<", se="<<seB<<endl;
06209
06210 Float_t sigCorDiff=1;
06211 if (iterB->second!=0){
06212
06213 sigCorDiff=iterA->second/iterB->second;
06214 }
06215 else{
06216 MSG("LIPlexMaps",Msg::kWarning)<<"Ahh, zero calib constant"<<endl;
06217 }
06218
06219
06220
06221 if (planeA==0){
06222 MAXMSG("LIPlexMaps",Msg::kWarning,1)
06223 <<"Cutting out plane 0. It's known to be bad!"<<endl;
06224 continue;
06225 }
06226 else if (planeA==25 && stripA==5){
06227 MAXMSG("LIPlexMaps",Msg::kWarning,1)
06228 <<"Cutting out plane 25, strip 5. It's used to be bad"<<endl;
06229 continue;
06230 }
06231 else if (planeA==35 && year==2002){
06232 MAXMSG("LIPlexMaps",Msg::kWarning,1)
06233 <<"Cutting out plane 35. It's bad in 2002"<<endl;
06234 continue;
06235 }
06236 else if ((planeA==56 || planeA==58) && seA==StripEnd::kWest &&
06237 year==2003){
06238 MAXMSG("LIPlexMaps",Msg::kWarning,1)
06239 <<"Cutting out plane 56 & 58. It's bad in 2003"<<endl;
06240 continue;
06241 }
06242 else if ((planeA==33 || planeA==35) && year==2003){
06243 MAXMSG("LIPlexMaps",Msg::kWarning,1)
06244 <<"Cutting out plane 33 & 35. It's bad in 2003"<<endl;
06245 continue;
06246 }
06247
06248
06249 if (seA==StripEnd::kEast){
06250 pStVsPlRatio1->Fill(planeA,stripA,sigCorDiff);
06251 }
06252 else if (seA==StripEnd::kWest){
06253 pStVsPlRatio2->Fill(planeA,stripA,sigCorDiff);
06254 }
06255
06256
06257 if (stripA>=22 || stripA<=1){
06258 MAXMSG("LIPlexMaps",Msg::kWarning,1)
06259 <<"Making fiducial volume cut on strip"<<endl;
06260 continue;
06261 }
06262
06263 hResponse->Fill(sigCorDiff);
06264 pRatioVsStrip->Fill(stripA,sigCorDiff);
06265 pRatioVsPlane->Fill(planeA,sigCorDiff);
06266 pRatioVsStripCoarse->Fill(stripA,sigCorDiff);
06267 if (planeA<=30) pRatioVsStripCoarseFront->Fill(stripA,sigCorDiff);
06268 if (planeA>30) pRatioVsStripCoarseBack->Fill(stripA,sigCorDiff);
06269 pRatioVsPlaneCoarse->Fill(planeA,sigCorDiff);
06270
06271 if (seA==StripEnd::kEast){
06272 pRatioVsStrip1->Fill(stripA,sigCorDiff);
06273 pRatioVsPlane1->Fill(planeA,sigCorDiff);
06274 if (planeA%2==0) pRatioVsStripE1->Fill(stripA,sigCorDiff);
06275 else if (planeA%2==1) pRatioVsStripO1->Fill(stripA,sigCorDiff);
06276 }
06277 else if (seA==StripEnd::kWest){
06278 pRatioVsStrip2->Fill(stripA,sigCorDiff);
06279 pRatioVsPlane2->Fill(planeA,sigCorDiff);
06280 if (planeA%2==0) pRatioVsStripE2->Fill(stripA,sigCorDiff);
06281 else if (planeA%2==1) pRatioVsStripO2->Fill(stripA,sigCorDiff);
06282 }
06283 }
06284
06285 TCanvas *cResponse=new TCanvas
06286 ("cResponse","cResponse",0,0,1000,800);
06287 cResponse->SetFillColor(0);
06288 cResponse->Divide(2,1);
06289 cResponse->cd(1);
06290 hResponse->Draw();
06291 cResponse->cd(2);
06292 hResponseErr->Draw();
06293
06294 TCanvas *cPlSt=new TCanvas
06295 ("cPlSt","cPlSt",0,0,800,1000);
06296 cPlSt->SetFillColor(0);
06297 cPlSt->Divide(1,2);
06298 cPlSt->cd(1);
06299 pRatioVsPlane->Draw();
06300 cPlSt->cd(2);
06301 pRatioVsStrip->Draw();
06302
06303 TCanvas *cPlStCoarse=new TCanvas
06304 ("cPlStCoarse","cPlStCoarse",0,0,800,1000);
06305 cPlStCoarse->SetFillColor(0);
06306 cPlStCoarse->Divide(1,2);
06307 cPlStCoarse->cd(1);
06308 pRatioVsPlaneCoarse->Draw();
06309 cPlStCoarse->cd(2);
06310 pRatioVsStripCoarse->Draw();
06311
06312 TCanvas *cStCoarse=new TCanvas
06313 ("cStCoarse","cStCoarse",0,0,800,1000);
06314 cStCoarse->SetFillColor(0);
06315 cStCoarse->Divide(1,2);
06316 cStCoarse->cd(1);
06317 pRatioVsStripCoarseFront->Draw();
06318 cStCoarse->cd(2);
06319 pRatioVsStripCoarseBack->Draw();
06320
06321 TCanvas *cPlSt1_2=new TCanvas
06322 ("cPlSt1_2","cPlSt1_2",0,0,1000,1000);
06323 cPlSt1_2->SetFillColor(0);
06324 cPlSt1_2->Divide(2,2);
06325 cPlSt1_2->cd(1);
06326 pRatioVsPlane1->Draw();
06327 cPlSt1_2->cd(2);
06328 pRatioVsPlane2->Draw();
06329 cPlSt1_2->cd(3);
06330 pRatioVsStrip1->Draw();
06331 cPlSt1_2->cd(4);
06332 pRatioVsStrip2->Draw();
06333
06334 TCanvas *cPlSt1_2OE=new TCanvas
06335 ("cPlSt1_2OE","cPlSt1_2OE",0,0,1000,1000);
06336 cPlSt1_2OE->SetFillColor(0);
06337 cPlSt1_2OE->Divide(2,2);
06338 cPlSt1_2OE->cd(1);
06339 pRatioVsStripO1->Draw();
06340 cPlSt1_2OE->cd(2);
06341 pRatioVsStripE1->Draw();
06342 cPlSt1_2OE->cd(3);
06343 pRatioVsStripO2->Draw();
06344 cPlSt1_2OE->cd(4);
06345 pRatioVsStripE2->Draw();
06346
06347 TCanvas *cStVsPl=new TCanvas
06348 ("cStVsPl","cStVsPl",0,0,800,800);
06349 cStVsPl->SetFillColor(0);
06350 cStVsPl->Divide(1,2);
06351 cStVsPl->cd(1);
06352 pStVsPlRatio1->Draw("colz");
06353 cStVsPl->cd(2);
06354 pStVsPlRatio2->Draw("colz");
06355
06356 MSG("LIPlexMaps",Msg::kInfo)
06357 <<endl<<" ** Finished the CompareStripToStrip() method... **"<<endl;
06358 }
06359
06360
06361
06362 void LIPlexMaps::ReadDbGains(Int_t det,SimFlag::ESimFlag simFlag,
06363 VldTimeStamp ts,std::string runNumber,std::string sAgg,Int_t task)
06364 {
06365
06366 MSG("LIPlexMaps",Msg::kInfo)
06367 <<endl<<" ** Running the ReadDbGains() method... ** "<<endl;
06368
06369
06370 string fileName=runNumber+"GainsDB.dat";
06371
06372 ofstream TextFile(fileName.c_str());
06373
06374
06375 this->SetDetector(det);
06376
06377
06378 LIPmt avM64SE1;
06379 LIPmt avM64SE2;
06380 LIPmt avM16VA0SE1;
06381 LIPmt avM16VA0SE2;
06382 LIPmt avM16VA1SE1;
06383 LIPmt avM16VA1SE2;
06384 LIPmt avM16VA2SE1;
06385 LIPmt avM16VA2SE2;
06386
06387
06388 avM64SE1.Initialise(64,1);
06389 avM64SE2.Initialise(64,1);
06390 avM16VA0SE1.Initialise(16,8);
06391 avM16VA0SE2.Initialise(16,8);
06392 avM16VA1SE1.Initialise(16,8);
06393 avM16VA1SE2.Initialise(16,8);
06394 avM16VA2SE1.Initialise(16,8);
06395 avM16VA2SE2.Initialise(16,8);
06396
06397
06398 vector<LIPmt*> vPmts;
06399 vPmts.push_back(&avM64SE1);
06400 vPmts.push_back(&avM64SE2);
06401 vPmts.push_back(&avM16VA0SE1);
06402 vPmts.push_back(&avM16VA0SE2);
06403 vPmts.push_back(&avM16VA1SE1);
06404 vPmts.push_back(&avM16VA1SE2);
06405 vPmts.push_back(&avM16VA2SE1);
06406 vPmts.push_back(&avM16VA2SE2);
06407
06408 Int_t* planeMax=new Int_t[NUMCRATES];
06409 Int_t* planeMin=new Int_t[NUMCRATES];
06410 fLookup.SetPbPlanes(planeMin,planeMax,det);
06411
06412
06413
06414 const Int_t firstStripBin=FIRSTSTRIP-8;
06415 const Int_t lastStripBin=LASTSTRIP+9;
06416 const Int_t bins=lastStripBin-firstStripBin;
06417
06418 string sConstantBit="";
06419
06420 MSG("LIAnalysis",Msg::kInfo)
06421 <<"sConstantBit="<<sConstantBit<<endl;
06422
06423 TH2F **hStripVsPlaneGain=0;
06424 hStripVsPlaneGain= new TH2F*[NUMCRATES];
06425 for (Int_t i=0;i<NUMCRATES;i++){
06426 string sPb=Form("%d",i);
06427 string sTs=ts.AsString("s");
06428
06429 fS="Gains (Crate "+sPb+")";
06430 hStripVsPlaneGain[i]=new TH2F(fS.c_str(),fS.c_str(),
06431 planeMax[i]-planeMin[i],
06432 planeMin[i],planeMax[i],
06433 bins,firstStripBin,lastStripBin);
06434 hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
06435 hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
06436 hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
06437 hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
06438 hStripVsPlaneGain[i]->SetFillColor(0);
06439
06440 }
06441
06442 TH2F **hAvDetGains=0;
06443 hAvDetGains= new TH2F*[NUMCRATES];
06444 for (Int_t i=0;i<NUMCRATES;i++){
06445 string sPb=Form("%d",i);
06446 string sTs=ts.AsString("s");
06447
06448 fS="Av Detector Gains (Crate "+sPb+")";
06449 hAvDetGains[i]=new TH2F(fS.c_str(),fS.c_str(),
06450 planeMax[i]-planeMin[i],
06451 planeMin[i],planeMax[i],
06452 bins,firstStripBin,lastStripBin);
06453 hAvDetGains[i]->GetXaxis()->SetTitle("Plane");
06454 hAvDetGains[i]->GetXaxis()->CenterTitle();
06455 hAvDetGains[i]->GetYaxis()->SetTitle("Strip");
06456 hAvDetGains[i]->GetYaxis()->CenterTitle();
06457 hAvDetGains[i]->SetFillColor(0);
06458
06459 }
06460
06461 TH2F **hStripVsPlaneGainErr=0;
06462 hStripVsPlaneGainErr= new TH2F*[NUMCRATES];
06463 for (Int_t i=0;i<NUMCRATES;i++){
06464 string sPb=Form("%d",i);
06465 fS="Gain Errors (Crate "+sPb+")";
06466 hStripVsPlaneGainErr[i]=new TH2F(fS.c_str(),fS.c_str(),
06467 planeMax[i]-planeMin[i],
06468 planeMin[i],planeMax[i],
06469 bins,firstStripBin,lastStripBin);
06470 hStripVsPlaneGainErr[i]->GetXaxis()->SetTitle("Plane");
06471 hStripVsPlaneGainErr[i]->GetXaxis()->CenterTitle();
06472 hStripVsPlaneGainErr[i]->GetYaxis()->SetTitle("Strip");
06473 hStripVsPlaneGainErr[i]->GetYaxis()->CenterTitle();
06474 hStripVsPlaneGainErr[i]->SetFillColor(0);
06475
06476 }
06477
06478 TH2F **hStripVsPlaneSPEWidth=0;
06479 hStripVsPlaneSPEWidth= new TH2F*[NUMCRATES];
06480 for (Int_t i=0;i<NUMCRATES;i++){
06481 string sPb=Form("%d",i);
06482 fS="Single PE Width (Crate "+sPb+")";
06483 hStripVsPlaneSPEWidth[i]=new TH2F(fS.c_str(),fS.c_str(),
06484 planeMax[i]-planeMin[i],
06485 planeMin[i],planeMax[i],
06486 bins,firstStripBin,lastStripBin);
06487 hStripVsPlaneSPEWidth[i]->GetXaxis()->SetTitle("Plane");
06488 hStripVsPlaneSPEWidth[i]->GetXaxis()->CenterTitle();
06489 hStripVsPlaneSPEWidth[i]->GetYaxis()->SetTitle("Strip");
06490 hStripVsPlaneSPEWidth[i]->GetYaxis()->CenterTitle();
06491 hStripVsPlaneSPEWidth[i]->SetFillColor(0);
06492
06493 }
06494
06495 TH1F *hGains=new TH1F("hGains","hGains",200,-1,200);
06496 hGains->GetXaxis()->SetTitle("Response of Stripends");
06497 hGains->GetXaxis()->CenterTitle();
06498 hGains->GetYaxis()->SetTitle("");
06499 hGains->GetYaxis()->CenterTitle();
06500 hGains->SetLineColor(2);
06501 hGains->SetFillStyle(3015);
06502 hGains->SetFillColor(2);
06503 hGains->SetLineWidth(3);
06504
06505
06506 TH1F *hGainsAll=new TH1F("hGainsAll","hGainsAll",400,-1,300);
06507 hGainsAll->GetXaxis()->SetTitle("Response of Stripends");
06508 hGainsAll->GetXaxis()->CenterTitle();
06509 hGainsAll->GetYaxis()->SetTitle("");
06510 hGainsAll->GetYaxis()->CenterTitle();
06511 hGainsAll->SetLineColor(2);
06512 hGainsAll->SetFillStyle(3015);
06513 hGainsAll->SetFillColor(2);
06514 hGainsAll->SetLineWidth(3);
06515 hGainsAll->SetBit(TH1::kCanRebin);
06516
06517 VldContext vldCtx(static_cast<Detector::Detector_t>(det),
06518 simFlag,ts);
06519 vldCtx.Print();
06520
06521
06522 PlexHandle plexHandle(vldCtx);
06523
06524 DbiResultPtr<CalADCtoPE> dbiCalADCtoPE;
06525 DbiResultPtr<CalADCtoPEs> dbiCalADCtoPEs;
06526
06527 UInt_t numRows=dbiCalADCtoPE.NewQuery(vldCtx,task);
06528 if(sAgg!="-1") numRows=dbiCalADCtoPEs.NewQuery(vldCtx,task);
06529
06530 MSG("LIPlexMaps",Msg::kInfo)<<endl
06531 <<"New DB query produced "<<numRows<<" rows"<<endl
06532 <<"Looping over rows..."<<endl;
06533
06534
06535 for(UInt_t i=0;i<numRows;i++) {
06536
06537 Float_t gain, gainErr, SPEWidth, SPEWidthErr;
06538 Int_t seId;
06539 UInt_t seidkey;
06540
06541 if(sAgg=="-1") {
06542 const CalADCtoPE* calAdcToPe = dbiCalADCtoPE.GetRow(i);
06543 gain=calAdcToPe->GetGain();
06544 gainErr=calAdcToPe->GetGainErr();
06545 SPEWidth=calAdcToPe->GetSPEWidth();
06546 seId=calAdcToPe->GetStripEndId();
06547 seidkey=calAdcToPe->GetSEIDkey();
06548 } else {
06549 const CalADCtoPEs* calAdcToPe = dbiCalADCtoPEs.GetRow(i);
06550 gain=calAdcToPe->GetGain();
06551 gainErr=calAdcToPe->GetGainErr();
06552 SPEWidth=calAdcToPe->GetSPEWidth();
06553 SPEWidthErr=calAdcToPe->GetSPEWidthErr();
06554 seidkey=calAdcToPe->GetSEIDkey();
06555 }
06556
06557 Int_t plane=-1;
06558 Int_t strip=-1;
06559 Int_t end=-1;
06560 fLookup.UnencodePlnStripEndKey(seidkey,static_cast<Detector::
06561 Detector_t>(det),plane,strip,end);
06562
06563
06564 hGains->Fill(gain);
06565 hGainsAll->Fill(gain);
06566
06567
06568 PlexStripEndId seid(static_cast<Detector::Detector_t>(det),
06569 plane,strip,
06570 static_cast<StripEnd::EStripEnd>(end));
06571
06572 PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
06573
06574 MSG("LIPlexMaps",Msg::kDebug)
06575 <<"pl="<<plane<<", st="<<strip<<", end="<<end
06576 <<", pix="<<pixSpotId.GetPixel()
06577 <<", pixSpot="<<pixSpotId.GetSpot()
06578 <<endl;
06579
06580 ElecType::Elec_t elecType=plexHandle.GetRawChannelId(seid).
06581 GetElecType();
06582 Int_t vaChip=plexHandle.GetRawChannelId(seid).GetVaChip();
06583
06584
06585
06586 if (elecType==ElecType::kQIE){
06587 if (plane%2==1) avM64SE1.AddMultiPoint(pixSpotId.GetPixel(),
06588 pixSpotId.GetSpot(),gain);
06589 else if (plane%2==0) avM64SE2.AddMultiPoint(pixSpotId.GetPixel(),
06590 pixSpotId.GetSpot(),gain);
06591 }
06592 else if (elecType==ElecType::kVA){
06593 if (vaChip==0){
06594 if (end==1) avM16VA0SE1.AddMultiPoint(pixSpotId.GetPixel(),
06595 pixSpotId.GetSpot(),gain);
06596 if (end==2) avM16VA0SE2.AddMultiPoint(pixSpotId.GetPixel(),
06597 pixSpotId.GetSpot(),gain);
06598 }
06599 else if (vaChip==1){
06600 if (end==1) avM16VA1SE1.AddMultiPoint(pixSpotId.GetPixel(),
06601 pixSpotId.GetSpot(),gain);
06602 if (end==2) avM16VA1SE2.AddMultiPoint(pixSpotId.GetPixel(),
06603 pixSpotId.GetSpot(),gain);
06604 }
06605 else if (vaChip==2){
06606 if (end==1) avM16VA2SE1.AddMultiPoint(pixSpotId.GetPixel(),
06607 pixSpotId.GetSpot(),gain);
06608 if (end==2) avM16VA2SE2.AddMultiPoint(pixSpotId.GetPixel(),
06609 pixSpotId.GetSpot(),gain);
06610 }
06611 }
06612
06613 PlexPixelSpotId pixelId=plexHandle.GetPixelSpotId(seid);
06614
06615 Int_t crate=plexHandle.GetRawChannelId(seid).GetCrate();
06616 Int_t Varc=plexHandle.GetRawChannelId(seid).GetVarcId();
06617 Int_t Vmm=plexHandle.GetRawChannelId(seid).GetVmm();
06618
06619 Int_t Vaadc=plexHandle.GetRawChannelId(seid).GetVaAdcSel();
06620 Int_t channel=plexHandle.GetRawChannelId(seid).GetVaChannel();
06621 Int_t pixel=static_cast<Int_t>(pixelId.GetPixel());
06622
06623 Int_t inRack=static_cast<Int_t>(pixelId.GetInRack());
06624 Int_t numericMuxBox=static_cast<Int_t>(pixelId.GetNumericMuxBox());
06625 Int_t rackBay=static_cast<Int_t>(pixelId.GetRackBay());
06626 Char_t rackLevel=static_cast<Char_t>(pixelId.GetRackLevel());
06627 Int_t tube=static_cast<Int_t>(pixelId.GetTube());
06628
06629
06630 TextFile<<plane<<"\t"<<strip<< "\t"<<end
06631 <<"\t" <<gain<<"\t" <<gainErr<<"\t" <<SPEWidth<<"\t"<<crate<<"\t"<<Varc<<"\t"<<Vmm<<"\t"<<Vaadc<<"\t"<<channel<<"\t"<<pixel
06632 <<"\t"<<vaChip<<"\t"<<inRack<<"\t"<<numericMuxBox
06633 <<"\t"<<rackBay<<"\t"<<rackLevel<<"\t"<<tube<<endl;
06634
06635 if (crate>=FIRSTCRATE && crate<=LASTCRATE){
06636 hStripVsPlaneGainErr[crate]->Fill(plane,strip,gainErr);
06637 hStripVsPlaneGain[crate]->Fill(plane,strip,gain);
06638 hStripVsPlaneSPEWidth[crate]->Fill(plane,strip,SPEWidth);
06639 }
06640
06641 Bool_t print=false;
06642 if (det==Detector::kCalDet) print=true;
06643 else if (det==Detector::kFar &&
06644 MsgService::Instance()->
06645 IsActive("LIPlexMaps",Msg::kDebug)) print=true;
06646 else if (det==Detector::kNear &&
06647 MsgService::Instance()->
06648 IsActive("LIPlexMaps",Msg::kDebug)) print=true;
06649
06650 if (print){
06651 MSG("LIPlexMaps",Msg::kInfo)
06652 <<"("<<plane<<";"<<strip<<";"<<end<<")"
06653 <<" Gain="<<gain<<", gainErr="<<gainErr<<", SPEW="<<SPEWidth<<endl;
06654
06655
06656 }
06657 }
06658
06659 for (vector<LIPmt*>::iterator it=vPmts.begin();
06660 it!=vPmts.end();it++) {
06661
06662 if ((*it)->IsEmpty()) cout<<"empty"<<endl;
06663 else{
06664 cout<<"not emp"<<endl;
06665 (*it)->Print();
06666 }
06667 }
06668
06669
06670
06671 for (Int_t pl=*planeMin;pl<*planeMax;pl++){
06672 for (Int_t st=-1;st<NUMSTRIPS+2;st++){
06673 for (Int_t se=0;se<NUMSIDES;se++){
06674
06675
06676 PlexStripEndId seid(static_cast<Detector::Detector_t>
06677 (det),pl,st,
06678 static_cast<StripEnd::EStripEnd>(se+1));
06679
06680
06681 PlexPixelSpotId psid=plexHandle.GetPixelSpotId(seid);
06682 ElecType::Elec_t elecType=plexHandle.GetRawChannelId(seid).
06683 GetElecType();
06684
06685 if (se+1==StripEnd::kWest && elecType==ElecType::kQIE){
06686
06687 Double_t gain=avM64SE2.GetPixelGain(psid.GetPixel());
06688
06689 hAvDetGains[1]->Fill(pl,st,gain);
06690 }
06691 }
06692 }
06693 }
06694
06695 gStyle->SetOptStat(1111111);
06696
06697
06698 if (!avM64SE1.IsEmpty() || !avM64SE2.IsEmpty()){
06699 TCanvas *cPmtFaceM64=new TCanvas
06700 ("cPmtFaceM64","cPmtFaceM64",0,0,1000,550);
06701 cPmtFaceM64->SetFillColor(0);
06702 cPmtFaceM64->Divide(2,1);
06703 cPmtFaceM64->cd(1);
06704 fS="M64 Gains (U view)";
06705 if (!avM64SE1.IsEmpty()) avM64SE1.GetPmtFaceMap(fS.c_str())->
06706 Draw("colztext");
06707 cPmtFaceM64->cd(2);
06708 fS="M64 Gains (V view)";
06709 if (!avM64SE2.IsEmpty()) avM64SE2.GetPmtFaceMap(fS.c_str())->
06710 Draw("colztext");
06711
06712 string sDbPmts="DbPmts";
06713 sDbPmts+=Detector::AsString(static_cast<Detector::
06714 Detector_t>(det));
06715 sDbPmts+=".ps";
06716 cPmtFaceM64->Print(sDbPmts.c_str());
06717
06718 }
06719
06720
06721 if (!avM16VA0SE1.IsEmpty() || !avM16VA0SE1.IsEmpty() ||
06722 !avM16VA1SE1.IsEmpty() || !avM16VA1SE1.IsEmpty() ||
06723 !avM16VA2SE1.IsEmpty() || !avM16VA2SE1.IsEmpty()){
06724
06725 TCanvas *cPmtFaceM16=new TCanvas
06726 ("cPmtFaceM16","cPmtFaceM16",0,0,1000,700);
06727 cPmtFaceM16->SetFillColor(0);
06728 cPmtFaceM16->Divide(3,2);
06729 cPmtFaceM16->cd(1);
06730 fS="M16 Gains (VA0, stripend1)";
06731 if (!avM16VA0SE1.IsEmpty()) avM16VA0SE1.GetPmtFaceMap(fS.c_str())->
06732 Draw("colztext");
06733 cPmtFaceM16->cd(2);
06734 fS="M16 Gains (VA1, stripend1)";
06735 if (!avM16VA1SE1.IsEmpty()) avM16VA1SE1.GetPmtFaceMap(fS.c_str())->
06736 Draw("colztext");
06737 cPmtFaceM16->cd(3);
06738 fS="M16 Gains (VA2, stripend1)";
06739 if (!avM16VA2SE1.IsEmpty()) avM16VA2SE1.GetPmtFaceMap(fS.c_str())->
06740 Draw("colztext");
06741 cPmtFaceM16->cd(4);
06742 fS="M16 Gains (VA0, stripend2)";
06743 if (!avM16VA0SE2.IsEmpty()) avM16VA0SE2.GetPmtFaceMap(fS.c_str())->
06744 Draw("colztext");
06745 cPmtFaceM16->cd(5);
06746 fS="M16 Gains (VA1, stripend2)";
06747 if (!avM16VA1SE2.IsEmpty()) avM16VA1SE2.GetPmtFaceMap(fS.c_str())->
06748 Draw("colztext");
06749 cPmtFaceM16->cd(6);
06750 fS="M16 Gains (VA2, stripend2)";
06751 if (!avM16VA2SE2.IsEmpty()) avM16VA2SE2.GetPmtFaceMap(fS.c_str())->
06752 Draw("colztext");
06753
06754 string sDbPmts="DbPmts";
06755 sDbPmts+=Detector::AsString(static_cast<Detector::
06756 Detector_t>(det));
06757 sDbPmts+=".ps";
06758 cPmtFaceM16->Print(sDbPmts.c_str());
06759
06760 }
06761
06762
06763 TCanvas *cAvDetGain=new TCanvas
06764 ("cAvDetGain","cAvDetGain",0,0,1000,800);
06765 cAvDetGain->SetFillColor(0);
06766 cAvDetGain->cd();
06767 hAvDetGains[1]->Draw("colz");
06768
06769
06770 gStyle->SetOptStat(0);
06771
06772
06773 TCanvas *cStripVsPlaneGain=new TCanvas
06774 ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);
06775 cStripVsPlaneGain->SetFillColor(0);
06776 cStripVsPlaneGain->cd();
06777 string sDbGains="DbGains";
06778 sDbGains+=Detector::AsString(static_cast<Detector::
06779 Detector_t>(det));
06780 sDbGains+=".ps";
06781 cStripVsPlaneGain->Print((sDbGains+"[").c_str());
06782 gErrorIgnoreLevel=1;
06783 for (Int_t i=0;i<NUMCRATES;i++){
06784 cStripVsPlaneGain->Clear();
06785 hStripVsPlaneGain[i]->Draw("colz");
06786 cStripVsPlaneGain->Print(sDbGains.c_str());
06787 }
06788 cStripVsPlaneGain->Print((sDbGains+"]").c_str());
06789 gErrorIgnoreLevel=0;
06790
06791
06792 TCanvas *cStripVsPlaneGainErr=new TCanvas
06793 ("cStripVsPlaneGainErr","StripVsPlane: GainErr",0,0,1000,800);
06794 cStripVsPlaneGainErr->SetFillColor(0);
06795 cStripVsPlaneGainErr->cd();
06796 string sDbGainErrs="DbGainErrs";
06797 sDbGainErrs+=Detector::AsString(static_cast<Detector::
06798 Detector_t>(det));
06799 sDbGainErrs+=".ps";
06800 cStripVsPlaneGainErr->Print((sDbGainErrs+"[").c_str());
06801 gErrorIgnoreLevel=1;
06802 for (Int_t i=0;i<NUMCRATES;i++){
06803 cStripVsPlaneGainErr->Clear();
06804 hStripVsPlaneGainErr[i]->Draw("colz");
06805 cStripVsPlaneGainErr->Print(sDbGainErrs.c_str());
06806 }
06807 cStripVsPlaneGainErr->Print((sDbGainErrs+"]").c_str());
06808 gErrorIgnoreLevel=0;
06809
06810
06811 TCanvas *cStripVsPlaneSPEWidth=new TCanvas
06812 ("cStripVsPlaneSPEWidth","StripVsPlane: SPEWidth",0,0,1000,800);
06813 cStripVsPlaneSPEWidth->SetFillColor(0);
06814 cStripVsPlaneSPEWidth->cd();
06815 string sDbSPEWidths="DbSPEWidths";
06816 sDbSPEWidths+=Detector::AsString(static_cast<Detector::
06817 Detector_t>(det));
06818 sDbSPEWidths+=".ps";
06819 cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"[").c_str());
06820 gErrorIgnoreLevel=1;
06821 for (Int_t i=0;i<NUMCRATES;i++){
06822 cStripVsPlaneSPEWidth->Clear();
06823 hStripVsPlaneSPEWidth[i]->Draw("colz");
06824 cStripVsPlaneSPEWidth->Print(sDbSPEWidths.c_str());
06825 }
06826 cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"]").c_str());
06827 gErrorIgnoreLevel=0;
06828
06829 if (det==Detector::kCalDet){
06830 TCanvas *cGain=new TCanvas("cGain","cGain",0,0,1000,800);
06831 cGain->SetFillColor(0);
06832 cGain->Divide(1,2);
06833 cGain->cd(1);
06834 hStripVsPlaneGain[0]->Draw("colz");
06835 cGain->cd(2);
06836 hStripVsPlaneGain[1]->Draw("colz");
06837 }
06838
06839 gStyle->SetOptStat(1111);
06840 TCanvas *cGain=new TCanvas("cGain","cGain",0,0,1000,800);
06841 cGain->SetFillColor(0);
06842 cGain->Divide(2,1);
06843 cGain->cd(1);
06844 hGains->Draw();
06845 cGain->cd(2);
06846 hGainsAll->Draw();
06847
06848 MSG("LIPlexMaps",Msg::kInfo)
06849 <<endl<<" ** Finished the ReadDbGains() method... ** "<<endl;
06850 }
06851
06852
06853
06855 Double_t LIPlexMaps::ReadDbGainAverage(Detector::Detector_t det, VldTimeStamp ts, VldTimeStamp *end, VldTimeStamp *start)
06856 {
06857
06858
06859 VldContext vldCtx(det, SimFlag::kData, ts);
06860
06861
06862
06863 DbiResultPtr<CalADCtoPEs> dbiCalADCtoPEs;
06864
06865
06866 Int_t task = 0;
06867 if (det == Detector::kNear) task = 1;
06868
06869
06870 UInt_t numRows = dbiCalADCtoPEs.NewQuery(vldCtx,task);
06871
06872
06873 Double_t gainaverage = 0.0;
06874 for (UInt_t i = 0; i < numRows; ++i)
06875 {
06876
06877 const CalADCtoPEs* calAdcToPe = dbiCalADCtoPEs.GetRow(i);
06878 Float_t gain = calAdcToPe->GetGain();
06879
06880 gainaverage += (gain - gainaverage) / (i+1);
06881 }
06882
06883
06884 VldTimeStamp endtime = dbiCalADCtoPEs.GetValidityRec()->GetVldRange().GetTimeEnd();
06885 VldTimeStamp starttime = dbiCalADCtoPEs.GetValidityRec()->GetVldRange().GetTimeStart();
06886
06887 if (end) *end = endtime;
06888 if (start) *start = starttime;
06889 return gainaverage;
06890 }
06891
06892
06893
06895 TH1D *LIPlexMaps::ReadDbGains(Detector::Detector_t det, VldTimeStamp ts)
06896 {
06897
06898 VldContext vldCtx(det, SimFlag::kData, ts);
06899
06900 DbiResultPtr<CalADCtoPEs> dbiCalADCtoPEs;
06901
06902
06903 Int_t task = 0;
06904 if (det == Detector::kNear) task = 1;
06905
06906
06907 UInt_t numRows = dbiCalADCtoPEs.NewQuery(vldCtx,task);
06908
06909 TH1D *detgains = new TH1D("detgains", "detgains", 200, 0, 200);
06910 if (det == Detector::kNear) {
06911 detgains->SetNameTitle("neargains", "Near Detector Gains");
06912 } else {
06913 detgains->SetNameTitle("fargains", "Far Detector Gains");
06914 }
06915
06916 for (UInt_t i = 0; i < numRows; ++i)
06917 {
06918 const CalADCtoPEs* calAdcToPe = dbiCalADCtoPEs.GetRow(i);
06919 Float_t gain = calAdcToPe->GetGain();
06920 detgains->Fill(gain);
06921 }
06922
06923 return detgains;
06924 }
06925
06926
06927
06928 void LIPlexMaps::ReadDbPulserDrift(Int_t det,VldTimeStamp ts)
06929 {
06930 MSG("LIPlexMaps",Msg::kInfo)
06931 <<endl<<" ** Running the ReadDbPulserDrift() method... ** "<<endl;
06932
06933
06934
06935 this->SetDetector(det);
06936
06937 Int_t* planeMax=new Int_t[NUMCRATES];
06938 Int_t* planeMin=new Int_t[NUMCRATES];
06939 fLookup.SetPbPlanes(planeMin,planeMax,det);
06940
06941 const Int_t firstStripBin=FIRSTSTRIP-8;
06942 const Int_t lastStripBin=LASTSTRIP+9;
06943 const Int_t bins=lastStripBin-firstStripBin;
06944
06945 string sConstantBit="";
06946
06947 MSG("LIAnalysis",Msg::kInfo)
06948 <<"sConstantBit="<<sConstantBit<<endl;
06949
06950 TH2F **hStripVsPlaneMean=0;
06951 hStripVsPlaneMean= new TH2F*[NUMCRATES];
06952 for (Int_t i=0;i<NUMCRATES;i++){
06953 string sPb=Form("%d",i);
06954 fS="Mean (Crate "+sPb+")";
06955 hStripVsPlaneMean[i]=new TH2F(fS.c_str(),fS.c_str(),
06956 planeMax[i]-planeMin[i],
06957 planeMin[i],planeMax[i],
06958 bins,firstStripBin,lastStripBin);
06959 hStripVsPlaneMean[i]->GetXaxis()->SetTitle("Plane");
06960 hStripVsPlaneMean[i]->GetXaxis()->CenterTitle();
06961 hStripVsPlaneMean[i]->GetYaxis()->SetTitle("Strip");
06962 hStripVsPlaneMean[i]->GetYaxis()->CenterTitle();
06963 hStripVsPlaneMean[i]->SetFillColor(0);
06964
06965 }
06966
06967 TH2F **hStripVsPlaneError=0;
06968 hStripVsPlaneError= new TH2F*[NUMCRATES];
06969 for (Int_t i=0;i<NUMCRATES;i++){
06970 string sPb=Form("%d",i);
06971 fS="Gain Error (Crate "+sPb+")";
06972 hStripVsPlaneError[i]=new TH2F(fS.c_str(),fS.c_str(),
06973 planeMax[i]-planeMin[i],
06974 planeMin[i],planeMax[i],
06975 bins,firstStripBin,lastStripBin);
06976 hStripVsPlaneError[i]->GetXaxis()->SetTitle("Plane");
06977 hStripVsPlaneError[i]->GetXaxis()->CenterTitle();
06978 hStripVsPlaneError[i]->GetYaxis()->SetTitle("Strip");
06979 hStripVsPlaneError[i]->GetYaxis()->CenterTitle();
06980 hStripVsPlaneError[i]->SetFillColor(0);
06981
06982 }
06983
06984 TH2F **hStripVsPlaneNumEntries=0;
06985 hStripVsPlaneNumEntries= new TH2F*[NUMCRATES];
06986 for (Int_t i=0;i<NUMCRATES;i++){
06987 string sPb=Form("%d",i);
06988 fS="NumEntries_Crate"+sPb;
06989 hStripVsPlaneNumEntries[i]=new TH2F(fS.c_str(),fS.c_str(),
06990 planeMax[i]-planeMin[i],
06991 planeMin[i],planeMax[i],
06992 bins,firstStripBin,lastStripBin);
06993 hStripVsPlaneNumEntries[i]->GetXaxis()->SetTitle("Plane");
06994 hStripVsPlaneNumEntries[i]->GetXaxis()->CenterTitle();
06995 hStripVsPlaneNumEntries[i]->GetYaxis()->SetTitle("Strip");
06996 hStripVsPlaneNumEntries[i]->GetYaxis()->CenterTitle();
06997 hStripVsPlaneNumEntries[i]->SetFillColor(0);
06998
06999 }
07000
07001 VldContext vldCtx(static_cast<Detector::Detector_t>(det),
07002 SimFlag::kData,ts);
07003 vldCtx.Print();
07004
07005
07006
07007 DbiResultPtr<PulserRefDrift> dbiPulserDrift;
07008
07009
07010 UInt_t numRows=dbiPulserDrift.NewQuery(vldCtx,0);
07011
07012 MSG("LIPlexMaps",Msg::kInfo)
07013 <<"New DB query produced "<<numRows<<" rows"<<endl
07014 <<"Looping over rows..."<<endl;
07015
07017
07019 for(UInt_t i=0;i<numRows;i++) {
07020
07021
07022 const PulserRefDrift* pulserDrift = dbiPulserDrift.GetRow(i);
07023
07024
07025 Float_t mean=pulserDrift->GetMean();
07026 Float_t error=pulserDrift->GetError();
07027 Float_t numEntries=pulserDrift->GetNumEntries();
07028
07029 UInt_t seidkey=pulserDrift->GetStripEnd();
07030 Int_t plane=-1;
07031 Int_t strip=-1;
07032 Int_t end=-1;
07033 fLookup.UnencodePlnStripEndKey(seidkey,static_cast<Detector::
07034 Detector_t>(det),plane,strip,end);
07035
07036 Int_t crate=Plane2Crate(plane,end,det);
07037 if (crate>=FIRSTCRATE && crate<=LASTCRATE){
07038 hStripVsPlaneMean[crate]->Fill(plane,strip,mean);
07039 hStripVsPlaneError[crate]->Fill(plane,strip,error);
07040 hStripVsPlaneNumEntries[crate]->Fill(plane,strip,numEntries);
07041 }
07042
07043 Bool_t print=false;
07044
07045 if (det==Detector::kCalDet) print=true;
07046 else if (det==Detector::kFar &&
07047 MsgService::Instance()->
07048 IsActive("LIPlexMaps",Msg::kDebug)) print=true;
07049 else if (det==Detector::kNear &&
07050 MsgService::Instance()->
07051 IsActive("LIPlexMaps",Msg::kDebug)) print=true;
07052
07053 if (print){
07054 MSG("LIPlexMaps",Msg::kInfo)
07055 <<"("<<plane<<";"<<strip<<";"<<end<<")"
07056 <<" Mean="<<mean<<", error="<<error<<", numEnt="<<numEntries
07057 <<", seidkey="<<seidkey<<endl;
07058 }
07059 }
07061
07063
07064
07065 gStyle->SetOptStat(0);
07066
07067
07068 TCanvas *cStripVsPlaneMean=new TCanvas
07069 ("cStripVsPlaneMean","StripVsPlane: Mean",0,0,1000,800);
07070 cStripVsPlaneMean->SetFillColor(0);
07071 cStripVsPlaneMean->cd();
07072 string sDbMeans="DbDrift";
07073 sDbMeans+=Detector::AsString(static_cast<Detector::
07074 Detector_t>(det));
07075 sDbMeans+=".ps";
07076 cStripVsPlaneMean->Print((sDbMeans+"[").c_str());
07077 gErrorIgnoreLevel=1;
07078
07079 gStyle->SetOptStat(0);
07080 for (Int_t i=0;i<NUMCRATES;i++){
07081 cStripVsPlaneMean->Clear();
07082 hStripVsPlaneMean[i]->Draw("colz");
07083 cStripVsPlaneMean->Print(sDbMeans.c_str());
07084 }
07085
07086 cStripVsPlaneMean->Print((sDbMeans+"]").c_str());
07087 gErrorIgnoreLevel=0;
07088
07089 TCanvas *cStripVsPlaneError=new TCanvas
07090 ("cStripVsPlaneError","StripVsPlane: Error",0,0,1000,800);
07091 cStripVsPlaneError->SetFillColor(0);
07092 cStripVsPlaneError->Divide(1,2);
07093 cStripVsPlaneError->cd(1);
07094 hStripVsPlaneError[0]->Draw("colz");
07095 cStripVsPlaneError->cd(2);
07096 hStripVsPlaneError[1]->Draw("colz");
07097
07098 TCanvas *cStripVsPlaneNumEntries=new TCanvas
07099 ("cStripVsPlaneNumEntries","StripVsPlane: NumEntries",
07100 0,0,1000,800);
07101 cStripVsPlaneNumEntries->SetFillColor(0);
07102 cStripVsPlaneNumEntries->Divide(1,2);
07103 cStripVsPlaneNumEntries->cd(1);
07104 hStripVsPlaneNumEntries[0]->Draw("colz");
07105 cStripVsPlaneNumEntries->cd(2);
07106 hStripVsPlaneNumEntries[1]->Draw("colz");
07107
07108 MSG("LIPlexMaps",Msg::kInfo)
07109 <<endl<<" ** Finished the ReadDbPulserDrift() method... ** "<<endl;
07110 }
07111
07112
07113
07114 void LIPlexMaps::DriftWithTime(VldRange vldRng,
07115 Float_t pointSpacingMinutes)
07116 {
07117 MSG("LIPlexMaps",Msg::kInfo)
07118 <<endl<<" ** Running the DriftWithTime method... ** "<<endl;
07119
07120
07121 VldTimeStamp startTime=vldRng.GetTimeStart();
07122 VldTimeStamp endTime=vldRng.GetTimeEnd();
07123 const Detector::Detector_t det=static_cast
07124 <Detector::Detector_t>(vldRng.GetDetectorMask());
07125 const SimFlag::ESimFlag simFlag=static_cast
07126 <SimFlag::ESimFlag>(vldRng.GetSimMask());
07127
07128
07129 VldContext startVldCtx(det,simFlag,startTime);
07130
07131
07132 if (det==Detector::kCalDet){
07133 fLookup.SetDetector(static_cast<Int_t>(det));
07134 }
07135 else if (det==Detector::kFar){
07136 fLookup.SetDetector(static_cast<Int_t>(det));
07137 }
07138 else if (det==Detector::kNear){
07139 fLookup.SetDetector(static_cast<Int_t>(det));
07140 }
07141 else{
07142 MSG("LIPlexMaps",Msg::kWarning)
07143 <<"Detector not supported="
07144 <<Detector::AsString(det)<<endl
07145 <<"Program will exit here..."<<endl;
07146 exit(1);
07147 }
07148
07149 DbiResultPtr<PulserRawDrift> dbiPulserDrift;
07150 DbiResultPtr<PulserRawDriftF> dbiPulserDriftF;
07151
07152 MSG("LIPlexMaps",Msg::kInfo)
07153 <<"Creating maps..."<<endl;
07154
07155 map<Int_t,LIPulserPin> refAdcPinRatio=this->
07156 GetRefAdcPinRatio(startVldCtx);
07157
07158 map<UInt_t,LIRun> stripEnds;
07159 map<PlexLedId,LIRun> pins;
07160
07161 VldContext* vldCtx=0;
07162 const PulserRawDrift *pulserDrift;
07163 const PulserRawDriftF *pulserDriftF;
07164 string sLastVldRange="Not set!";
07165
07166
07167 StripEnd::EStripEnd stripEndType=StripEnd::kUnknown;
07168 StripEnd::EStripEnd stripEndTypeF=StripEnd::kUnknown;
07169
07170
07171 PlexHandle* plexHandle=0;
07172
07173 Int_t pointSpacingSecs=static_cast<Int_t>(pointSpacingMinutes*60);
07174 Int_t startTimeSecs=startTime.GetSec();
07175 Int_t endTimeSecs=endTime.GetSec();
07176 Int_t secCounter=startTimeSecs;
07177
07178 MSG("LIPlexMaps",Msg::kInfo)
07179 <<"Starting main loop over vld range..."<<endl;
07180 while(secCounter<endTimeSecs){
07181 VldTimeStamp currentLoopTime(secCounter,0);
07182
07183
07184 if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kInfo)){
07185 MSG("LIPlexMaps",Msg::kInfo)<<"New Loop ";
07186 currentLoopTime.Print();
07187 }
07188 vldCtx=new VldContext(Detector::kCalDet,SimFlag::kData,
07189 currentLoopTime);
07190
07191
07192 map<Int_t,LIPulserPin> tempRefAdcPinRatio=
07193 this->GetRefAdcPinRatio(*vldCtx);
07194 if (tempRefAdcPinRatio.size()>0){
07195 refAdcPinRatio=tempRefAdcPinRatio;
07196 MSG("LIPlexMaps",Msg::kInfo)
07197 <<"New pin reference point, regenerated map"<<endl;
07198 }
07199 else{
07200 MSG("LIPlexMaps",Msg::kDebug)
07201 <<"Checked for new pin reference point, doing nothing"
07202 <<" because same as before"<<endl;
07203 }
07204
07205
07206 plexHandle=new PlexHandle(*vldCtx);
07207
07208 UInt_t numRows=dbiPulserDrift.NewQuery(*vldCtx,0);
07209
07210 if (numRows!=static_cast<UInt_t>(NUMPLANES*NUMSTRIPS*NUMENDS)){
07211 MSG("LIPlexMaps",Msg::kWarning)
07212 <<"PulserRawDrift only contains "<<numRows<<" rows"
07213 <<", it should have "<<NUMPLANES*NUMSTRIPS*NUMENDS<<endl;
07214 }
07215
07216 string sVldRange=dbiPulserDrift.GetValidityRec()->GetVldRange().
07217 AsString();
07218
07219 MSG("LIPlexMaps",Msg::kVerbose)
07220 <<"Vld range = "<<sVldRange<<endl;
07221
07222 if (sVldRange==sLastVldRange){
07223 MSG("LIPlexMaps",Msg::kInfo)
07224 <<"Skipping this point because validity range is the same"
07225 <<" as the previous point"<<endl;
07226 MSG("LIPlexMaps",Msg::kDebug)
07227 <<endl
07228 <<"VldRange="<<sVldRange<<endl
07229 <<"Previous VldRange="<<sLastVldRange<<endl;
07230
07231 sLastVldRange=sVldRange;
07232
07233
07234 secCounter+=pointSpacingSecs;
07235
07236
07237 delete vldCtx;
07238 delete plexHandle;
07239 continue;
07240 }
07241
07242
07243 sLastVldRange=sVldRange;
07244
07245 map<Int_t,Float_t> rawPin=this->GetRawPinMap(*vldCtx);
07246 map<PlexLedId,LIPulserPin> rawPinLedMap=this->
07247 GetRawPinLedMap(*vldCtx);
07248 UInt_t numRowsF=dbiPulserDriftF.NewQuery(*vldCtx,0);
07249
07250 if (numRows!=numRowsF){
07251 MSG("LIPlexMaps",Msg::kInfo)
07252 <<"Near and far end tables are different sizes! Near="
07253 <<numRows<<", far="<<numRowsF<<endl;
07254 }
07255
07257
07259 for(Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
07260 for(Int_t led=FIRSTLED;led<=LASTLED;led++){
07261
07262 PlexLedId ledId(det,pb,led);
07263
07264
07265 pins[ledId].AddPoint
07266 (secCounter,rawPinLedMap[ledId].mean,
07267 rawPinLedMap[ledId].error,rawPinLedMap[ledId].numEnt);
07268
07269 MSG("LIPlexMaps",Msg::kDebug)
07270 <<"Adding point to lirun "<<rawPinLedMap[ledId].mean<<endl;
07271 }
07272 }
07275
07276 for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
07277
07278
07279 if (pl>5) continue;
07280
07281 for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
07282 for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
07283
07284 if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
07285 else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
07286
07287 if (end==StripEnd::kEast) stripEndTypeF=StripEnd::kWest;
07288 else if(end==StripEnd::kWest) stripEndTypeF=StripEnd::kEast;
07289
07290 PlexStripEndId stripEndId(det,pl,st,stripEndType);
07291 PlexStripEndId stripEndIdF(det,pl,st,stripEndTypeF);
07292
07293
07294 if (!this->IsScintStrip(stripEndId,plexHandle)) continue;
07295
07296 pulserDrift=0;
07297 pulserDrift=dbiPulserDrift.GetRowByIndex
07298 (stripEndId.BuildPlnStripEndKey());
07299
07300 pulserDriftF=0;
07301 pulserDriftF=dbiPulserDriftF.GetRowByIndex
07302 (stripEndIdF.BuildPlnStripEndKey());
07303
07304 if (pulserDrift){
07305 Float_t mean=pulserDrift->GetMean();
07306 Float_t error=pulserDrift->GetError();
07307 Float_t numEntries=pulserDrift->GetNumEntries();
07308 UInt_t seidkey=pulserDrift->GetStripEnd();
07309
07310 Float_t meanF=-1;
07311 Float_t errorF=-1;
07312 Float_t numEntriesF=-1;
07313
07314 if (pulserDriftF){
07315 meanF=pulserDriftF->GetMean();
07316 errorF=pulserDriftF->GetError();
07317 numEntriesF=pulserDriftF->GetNumEntries();
07318 }
07319
07320 Float_t nearOverFar=-1;
07321 if (meanF>0){
07322 if (stripEndType==StripEnd::kWest){
07323 nearOverFar=mean/meanF;
07324 }
07325 else if (stripEndType==StripEnd::kEast){
07326 nearOverFar=meanF/mean;
07327 }
07328 }
07329
07330 Float_t adcPinRatio=-1;
07331 if (rawPin[seidkey]>0){
07332 adcPinRatio=mean/rawPin[seidkey];
07333 }
07334 else {
07335 MSG("LIPlexMaps",Msg::kDebug)
07336 <<"Raw pin has zero mean!"<<endl;
07337 }
07338
07339 Float_t gainDrift=-1;
07340 if (refAdcPinRatio[seidkey].mean>0){
07341 if (adcPinRatio>0){
07342 gainDrift=adcPinRatio/refAdcPinRatio[seidkey].mean;
07343 }
07344 }
07345 else {
07346 MSG("LIPlexMaps",Msg::kWarning)
07347 <<"Ref ADC/PIN ratio has zero mean!"<<endl;
07348 }
07349
07350 MSG("LIPlexMaps",Msg::kDebug)
07351 <<"Gain drift="<<gainDrift<<endl;
07352
07353 if (numEntries>500 && gainDrift>0){
07354 stripEnds[seidkey].AddPoint(secCounter,mean,error,
07355 numEntries,gainDrift,
07356 nearOverFar);
07357 }
07358
07359 Int_t plane=-1;
07360 Int_t strip=-1;
07361 Int_t end=-1;
07362 fLookup.UnencodePlnStripEndKey(seidkey,det,plane,strip,
07363 end);
07364
07365 string sMean=Form("%.1f",mean);
07366 string sError=Form("%.2f",error);
07367 string sNumEntries=Form("%.0f",numEntries);
07368 string sSeId=Form("%d",seidkey);
07369
07370 MSG("LIPlexMaps",Msg::kDebug)
07371 <<"("<<plane<<";"<<strip<<";"<<end<<")"
07372 <<" Mean="<<sMean<<", error="<<sError
07373 <<", numEnt="<<sNumEntries
07374 <<", seidkey="<<sSeId<<endl;
07375 }
07376 }
07377 }
07378 }
07379
07380
07381 secCounter+=pointSpacingSecs;
07382
07383
07384 delete vldCtx;
07385 delete plexHandle;
07386 }
07387
07388
07389 MSG("LIPlexMaps",Msg::kInfo)
07390 <<"Finished main loop over vld range"<<endl;
07391
07392
07393 Int_t canvasXmax=1200;
07394 Int_t canvasYmax=600;
07395
07396
07397 TCanvas *cMeanVsTime=new TCanvas("cMeanVsTime","MeanVsTime",
07398 0,0,canvasXmax,canvasYmax);
07399 cMeanVsTime->SetFillColor(0);
07400 TCanvas *cErrorVsTime=new TCanvas("cErrorVsTime","ErrorVsTime",
07401 0,0,canvasXmax,canvasYmax);
07402 cErrorVsTime->SetFillColor(0);
07403 TCanvas *cNumEntVsTime=new TCanvas("cNumEntVsTime","NumEntVsTime",
07404 0,0,canvasXmax,canvasYmax);
07405 cNumEntVsTime->SetFillColor(0);
07406 TCanvas *cGainDriftVsTime=new TCanvas("cGainDriftVsTime",
07407 "GainDriftVsTime",
07408 0,0,canvasXmax,canvasYmax);
07409 cGainDriftVsTime->SetFillColor(0);
07410 TCanvas *cGainDriftVsTimeZoom=new TCanvas("cGainDriftVsTimeZoom",
07411 "GainDriftVsTimeZoom",
07412 0,0,canvasXmax,canvasYmax);
07413 cGainDriftVsTimeZoom->SetFillColor(0);
07414 TCanvas *cPinVsTime=new TCanvas("cPinVsTime","PinVsTime",
07415 0,0,canvasXmax,canvasYmax);
07416 cPinVsTime->SetFillColor(0);
07417 TCanvas *cNormPinVsTime=new TCanvas("cNormPinVsTime","NormPinVsTime",
07418 0,0,canvasXmax,canvasYmax);
07419 cNormPinVsTime->SetFillColor(0);
07420 TCanvas *cNormPinVsTimeZoom=new TCanvas("cNormPinVsTimeZoom",
07421 "NormPinVsTimeZoom",
07422 0,0,canvasXmax,canvasYmax);
07423 cNormPinVsTimeZoom->SetFillColor(0);
07424 TCanvas *cPinErrorVsTime=new TCanvas("cPinErrorVsTime",
07425 "PinErrorVsTime",
07426 0,0,canvasXmax,canvasYmax);
07427 cPinErrorVsTime->SetFillColor(0);
07428 TCanvas *cPinNumEntVsTime=new TCanvas("cPinNumEntVsTime",
07429 "PinNumEntVsTime",
07430 0,0,canvasXmax,canvasYmax);
07431 cPinNumEntVsTime->SetFillColor(0);
07432 TCanvas *cNearOverFarVsTime=new TCanvas("cNearOverFarVsTime",
07433 "NearOverFarVsTime",
07434 0,0,canvasXmax,canvasYmax);
07435 cNearOverFarVsTime->SetFillColor(0);
07436 TCanvas *cNormNearOverFarVsTime=new TCanvas("cNormNearOverFarVsTime",
07437 "NormNearOverFarVsTime",
07438 0,0,canvasXmax,canvasYmax);
07439 cNormNearOverFarVsTime->SetFillColor(0);
07440
07441 string sMeanVsTime="MeanVsTime.ps";
07442 string sErrorVsTime="ErrorVsTime.ps";
07443 string sNumEntVsTime="NumEntVsTime.ps";
07444 string sGainDriftVsTime="GainDriftVsTime.ps";
07445 string sGainDriftVsTimeZoom="GainDriftVsTimeZoom.ps";
07446 string sPinVsTime="PinVsTime.ps";
07447 string sNormPinVsTime="NormPinVsTime.ps";
07448 string sNormPinVsTimeZoom="NormPinVsTimeZoom.ps";
07449 string sPinErrorVsTime="PinErrorVsTime.ps";
07450 string sPinNumEntVsTime="PinNumEntVsTime.ps";
07451 string sNearOverFarVsTime="NearOverFarVsTime.ps";
07452 string sNormNearOverFarVsTime="NormNearOverFarVsTime.ps";
07453
07454
07455 cMeanVsTime->Print((sMeanVsTime+"[").c_str());
07456 cErrorVsTime->Print((sErrorVsTime+"[").c_str());
07457 cNumEntVsTime->Print((sNumEntVsTime+"[").c_str());
07458 cGainDriftVsTime->Print((sGainDriftVsTime+"[").c_str());
07459 cGainDriftVsTimeZoom->Print((sGainDriftVsTimeZoom+"[").c_str());
07460 cPinVsTime->Print((sPinVsTime+"[").c_str());
07461 cNormPinVsTime->Print((sNormPinVsTime+"[").c_str());
07462 cNormPinVsTimeZoom->Print((sNormPinVsTimeZoom+"[").c_str());
07463 cPinErrorVsTime->Print((sPinErrorVsTime+"[").c_str());
07464 cPinNumEntVsTime->Print((sPinNumEntVsTime+"[").c_str());
07465 cNearOverFarVsTime->Print((sNearOverFarVsTime+"[").c_str());
07466 cNormNearOverFarVsTime->Print((sNormNearOverFarVsTime+"[").c_str());
07467
07468 gErrorIgnoreLevel=1;
07469
07471
07473 map<PlexLedId,LIRun>::iterator pinIt=pins.begin();
07474
07475 MSG("LIPlexMaps",Msg::kInfo)
07476 <<"Iterating over the pins..."<<endl;
07477 while(pinIt!=pins.end()){
07478
07479
07480
07481 vector<Double_t> vTime=pinIt->second.GetPh();
07482 vector<Double_t> vMean=pinIt->second.GetAdc();
07483 vector<Double_t> vError=pinIt->second.GetPin(1);
07484 vector<Double_t> vNumEnt=pinIt->second.GetPin(2);
07485
07486 TGraph* gPinVsTime=0;
07487 TGraph* gNormPinVsTime=0;
07488 TGraph* gNormPinVsTimeZoom=0;
07489 TGraph* gPinErrorVsTime=0;
07490 TGraph* gPinNumEntVsTime=0;
07491
07492 gPinVsTime=TGraphVect(vTime,vMean);
07493 gPinErrorVsTime=TGraphVect(vTime,vError);
07494 gPinNumEntVsTime=TGraphVect(vTime,vNumEnt);
07495
07496 string sPb=Form("%d",pinIt->first.GetPulserBox());
07497 string sLed=Form("%d",pinIt->first.GetLedInBox());
07498
07499 MSG("LIPlexMaps",Msg::kInfo)
07500 <<"Printing ("<<sPb<<":"<<sLed<<")"
07501 <<" to postscript"<<endl;
07502
07503 cPinVsTime->cd();
07504 cPinVsTime->Clear();
07505 fS="Light level drifts (PIN ADC) with time (PB,LED)=("+
07506 sPb+","+sLed+")";
07507 gPinVsTime->Draw("AP");
07508 gPinVsTime->SetTitle(fS.c_str());
07509 gPinVsTime->GetYaxis()->SetTitle("Pin ADC");
07510 gPinVsTime->GetYaxis()->CenterTitle();
07511 this->SetGraphAxisEtc(gPinVsTime,startTimeSecs,endTimeSecs);
07512
07513
07514 this->NormaliseVector(vMean,2);
07515 gNormPinVsTime=TGraphVect(vTime,vMean);
07516 gNormPinVsTimeZoom=TGraphVect(vTime,vMean);
07517
07518 cNormPinVsTime->cd();
07519 cNormPinVsTime->Clear();
07520 fS="Fractional Drifts in PIN ADC with time (PB,LED)=("+
07521 sPb+","+sLed+")";
07522 gNormPinVsTime->Draw("AP");
07523 gNormPinVsTime->SetTitle(fS.c_str());
07524 gNormPinVsTime->GetYaxis()->SetTitle("Normalised Pin ADC");
07525 gNormPinVsTime->GetYaxis()->CenterTitle();
07526 this->SetGraphAxisEtc(gNormPinVsTime,startTimeSecs,endTimeSecs);
07527
07528 cNormPinVsTimeZoom->cd();
07529 cNormPinVsTimeZoom->Clear();
07530 fS="Fractional Drifts in PIN ADC with time, zoomed (PB,LED)=("+
07531 sPb+","+sLed+")";
07532 gNormPinVsTimeZoom->Draw("AP");
07533 gNormPinVsTimeZoom->SetTitle(fS.c_str());
07534 gNormPinVsTimeZoom->GetYaxis()->SetTitle("Normalised Pin ADC");
07535 gNormPinVsTimeZoom->GetYaxis()->CenterTitle();
07536 this->SetGraphAxisEtc(gNormPinVsTimeZoom,startTimeSecs,endTimeSecs);
07537 gNormPinVsTimeZoom->SetMinimum(0.97);
07538 gNormPinVsTimeZoom->SetMaximum(1.03);
07539
07540
07541
07542 cPinErrorVsTime->cd();
07543 cPinErrorVsTime->Clear();
07544 fS="Error on the PIN vs time (PB,LED)=("+
07545 sPb+","+sLed+")";
07546 gPinErrorVsTime->Draw("AP");
07547 gPinErrorVsTime->SetTitle(fS.c_str());
07548 gPinErrorVsTime->GetYaxis()->SetTitle("PinError in ADCs");
07549 gPinErrorVsTime->GetYaxis()->CenterTitle();
07550 this->SetGraphAxisEtc(gPinErrorVsTime,startTimeSecs,endTimeSecs);
07551
07552 cPinNumEntVsTime->cd();
07553 cPinNumEntVsTime->Clear();
07554 fS="PIN Number of Entries vs Time (PB,LED)=("+
07555 sPb+","+sLed+")";
07556 gPinNumEntVsTime->Draw("AP");
07557 gPinNumEntVsTime->SetTitle(fS.c_str());
07558 gPinNumEntVsTime->GetYaxis()->SetTitle("Pin's Number of Entries");
07559 gPinNumEntVsTime->GetYaxis()->CenterTitle();
07560 this->SetGraphAxisEtc(gPinNumEntVsTime,startTimeSecs,endTimeSecs);
07561
07562
07563 cPinVsTime->Print(sPinVsTime.c_str());
07564 cNormPinVsTime->Print(sNormPinVsTime.c_str());
07565 cNormPinVsTimeZoom->Print(sNormPinVsTimeZoom.c_str());
07566 cPinErrorVsTime->Print(sPinErrorVsTime.c_str());
07567 cPinNumEntVsTime->Print(sPinNumEntVsTime.c_str());
07568
07569
07570 delete gPinVsTime;
07571 delete gNormPinVsTime;
07572 delete gNormPinVsTimeZoom;
07573 delete gPinErrorVsTime;
07574 delete gPinNumEntVsTime;
07575
07576
07577 pinIt++;
07578 }
07579 MSG("LIPlexMaps",Msg::kInfo)
07580 <<"Finished iterating over the pins"<<endl;
07581
07583
07585 map<UInt_t,LIRun>::iterator seIt=stripEnds.begin();
07586 Int_t pageCounter=0;
07587
07588 MSG("LIPlexMaps",Msg::kInfo)
07589 <<endl<<"Iterating over the stripends..."
07590 <<endl<<"Map size="<<stripEnds.size()<<endl;
07591 while(seIt!=stripEnds.end()){
07592
07593 Int_t seidkey=seIt->first;
07594 Int_t plane=-1;
07595 Int_t strip=-1;
07596 Int_t end=-1;
07597 fLookup.UnencodePlnStripEndKey(seidkey,det,plane,strip,end);
07598
07599 string sPlane=Form("%d",plane);
07600 string sStrip=Form("%d",strip);
07601 string sEnd=Form("%d",end);
07602
07603
07604
07605 vector<Double_t> vTime=seIt->second.GetPh();
07606 vector<Double_t> vMean=seIt->second.GetAdc();
07607 vector<Double_t> vError=seIt->second.GetPin(1);
07608 vector<Double_t> vNumEnt=seIt->second.GetPin(2);
07609 vector<Double_t> vGainDrift=seIt->second.GetAdcF();
07610 vector<Double_t> vGainDriftZoom=seIt->second.GetAdcF();
07611 vector<Double_t> vNearOverFar=seIt->second.GetAdcLow();
07612
07613 TGraph* gMeanVsTime=0;
07614 TGraph* gErrorVsTime=0;
07615 TGraph* gNumEntVsTime=0;
07616 TGraph* gGainDriftVsTime=0;
07617 TGraph* gGainDriftVsTimeZoom=0;
07618 TGraph* gNearOverFarVsTime=0;
07619 TGraph* gNormNearOverFarVsTime=0;
07620
07621 gMeanVsTime=TGraphVect(vTime,vMean);
07622 gErrorVsTime=TGraphVect(vTime,vError);
07623 gNumEntVsTime=TGraphVect(vTime,vNumEnt);
07624 gGainDriftVsTime=TGraphVect(vTime,vGainDrift);
07625 gGainDriftVsTimeZoom=TGraphVect(vTime,vGainDriftZoom);
07626
07627 gNearOverFarVsTime=0;
07628 if (vNearOverFar.size()>0){
07629 gNearOverFarVsTime=TGraphVect(vTime,vNearOverFar);
07630 }
07631
07632 if (gMeanVsTime){
07633 cMeanVsTime->cd();
07634 cMeanVsTime->Clear();
07635 fS="Mean drifting with time (Pl,St,End)=("+sPlane+","+sStrip+","+
07636 sEnd+")";
07637 gMeanVsTime->Draw("AP");
07638 gMeanVsTime->SetTitle(fS.c_str());
07639 gMeanVsTime->GetYaxis()->SetTitle("Mean ADC");
07640 gMeanVsTime->GetYaxis()->CenterTitle();
07641 this->SetGraphAxisEtc(gMeanVsTime,startTimeSecs,endTimeSecs);
07642 }
07643 else{
07644
07645 seIt++;
07646 MSG("LIPlexMaps",Msg::kInfo)
07647 <<"Skipping: ("<<plane<<";"<<strip<<";"<<end<<")"<<endl;
07648 continue;
07649 }
07650
07651 if (gErrorVsTime){
07652 cErrorVsTime->cd();
07653 cErrorVsTime->Clear();
07654 fS="Error on mean over time (Pl,St,End)=("+sPlane+","+sStrip+","+
07655 sEnd+")";
07656 gErrorVsTime->Draw("AP");
07657 gErrorVsTime->SetTitle(fS.c_str());
07658 gErrorVsTime->GetYaxis()->SetTitle("Error (ADCs)");
07659 gErrorVsTime->GetYaxis()->CenterTitle();
07660 this->SetGraphAxisEtc(gErrorVsTime,startTimeSecs,endTimeSecs);
07661 }
07662
07663 if (gNumEntVsTime){
07664 cNumEntVsTime->cd();
07665 cNumEntVsTime->Clear();
07666 fS="NumEnt over time (Pl,St,End)=("+sPlane+","+sStrip+","+
07667 sEnd+")";
07668 gNumEntVsTime->Draw("AP");
07669 gNumEntVsTime->SetTitle(fS.c_str());
07670 gNumEntVsTime->GetYaxis()->SetTitle("NumEnt");
07671 gNumEntVsTime->GetYaxis()->CenterTitle();
07672 this->SetGraphAxisEtc(gNumEntVsTime,startTimeSecs,endTimeSecs);
07673 }
07674
07675 if (gGainDriftVsTime){
07676 cGainDriftVsTime->cd();
07677 cGainDriftVsTime->Clear();
07678 fS="Gain drift over time (Pl,St,End)=("+sPlane+","+sStrip+","+
07679 sEnd+")";
07680 gGainDriftVsTime->Draw("AP");
07681 gGainDriftVsTime->SetTitle(fS.c_str());
07682 gGainDriftVsTime->GetYaxis()->SetTitle("Gain Drift");
07683 gGainDriftVsTime->GetYaxis()->CenterTitle();
07684 this->SetGraphAxisEtc(gGainDriftVsTime,startTimeSecs,
07685 endTimeSecs);
07686 }
07687
07688 if (gGainDriftVsTimeZoom){
07689 cGainDriftVsTimeZoom->cd();
07690 cGainDriftVsTimeZoom->Clear();
07691 fS="Gain drift over time - zoomed (Pl,St,End)=("+
07692 sPlane+","+sStrip+","+sEnd+")";
07693 gGainDriftVsTimeZoom->Draw("AP");
07694 gGainDriftVsTimeZoom->SetTitle(fS.c_str());
07695 gGainDriftVsTimeZoom->GetYaxis()->SetTitle("Gain Drift");
07696 gGainDriftVsTimeZoom->GetYaxis()->CenterTitle();
07697 this->SetGraphAxisEtc(gGainDriftVsTimeZoom,startTimeSecs,
07698 endTimeSecs);
07699 gGainDriftVsTimeZoom->SetMaximum(1.11);
07700 gGainDriftVsTimeZoom->SetMinimum(0.89);
07701 }
07702
07703 if (gNearOverFarVsTime){
07704 cNearOverFarVsTime->cd();
07705 cNearOverFarVsTime->Clear();
07706 fS="Ratio of ND/FD vs Time (Pl,St,End)=("+
07707 sPlane+","+sStrip+","+sEnd+")";
07708 gNearOverFarVsTime->Draw("AP");
07709 gNearOverFarVsTime->SetTitle(fS.c_str());
07710 gNearOverFarVsTime->GetYaxis()->SetTitle("Ratio ND/FD");
07711 gNearOverFarVsTime->GetYaxis()->CenterTitle();
07712 this->SetGraphAxisEtc(gNearOverFarVsTime,startTimeSecs,
07713 endTimeSecs);
07714 }
07715
07716 gNormNearOverFarVsTime=0;
07717 if (vNearOverFar.size()>0){
07718 this->NormaliseVector(vNearOverFar);
07719 gNormNearOverFarVsTime=TGraphVect(vTime,vNearOverFar);
07720 }
07721
07722 if (gNormNearOverFarVsTime){
07723 cNormNearOverFarVsTime->cd();
07724 cNormNearOverFarVsTime->Clear();
07725 fS="Ratio of Normalised ND/FD vs Time (Pl,St,End)=("+
07726 sPlane+","+sStrip+","+sEnd+")";
07727 gNormNearOverFarVsTime->Draw("AP");
07728 gNormNearOverFarVsTime->SetTitle(fS.c_str());
07729 gNormNearOverFarVsTime->GetYaxis()->SetTitle("Ratio ND/FD");
07730 gNormNearOverFarVsTime->GetYaxis()->CenterTitle();
07731 this->SetGraphAxisEtc(gNormNearOverFarVsTime,startTimeSecs,
07732 endTimeSecs);
07733 }
07734
07735
07736 cMeanVsTime->Print(sMeanVsTime.c_str());
07737 cErrorVsTime->Print(sErrorVsTime.c_str());
07738 cNumEntVsTime->Print(sNumEntVsTime.c_str());
07739 cGainDriftVsTime->Print(sGainDriftVsTime.c_str());
07740 cGainDriftVsTimeZoom->Print(sGainDriftVsTimeZoom.c_str());
07741 cNearOverFarVsTime->Print(sNearOverFarVsTime.c_str());
07742 cNormNearOverFarVsTime->Print(sNormNearOverFarVsTime.c_str());
07743
07744
07745 MSG("LIPlexMaps",Msg::kVerbose)
07746 <<"Deleting graphs..."<<endl;
07747 delete gMeanVsTime;
07748 delete gErrorVsTime;
07749 delete gNumEntVsTime;
07750 delete gGainDriftVsTime;
07751 delete gGainDriftVsTimeZoom;
07752 delete gNearOverFarVsTime;
07753 delete gNormNearOverFarVsTime;
07754
07755 pageCounter++;
07756 if (pageCounter%50==0){
07757 MSG("LIPlexMaps",Msg::kInfo)
07758 <<"Number of pages = "<<pageCounter<<endl;
07759 }
07760 else {
07761 MSG("LIPlexMaps",Msg::kVerbose)
07762 <<"Number of pages = "<<pageCounter<<endl;
07763 }
07764
07765
07766 seIt++;
07767 }
07768
07769
07770 gErrorIgnoreLevel=0;
07771 cMeanVsTime->Print((sMeanVsTime+"]").c_str());
07772 cErrorVsTime->Print((sErrorVsTime+"]").c_str());
07773 cNumEntVsTime->Print((sNumEntVsTime+"]").c_str());
07774 cGainDriftVsTime->Print((sGainDriftVsTime+"]").c_str());
07775 cGainDriftVsTimeZoom->Print((sGainDriftVsTimeZoom+"]").c_str());
07776 cNearOverFarVsTime->Print((sNearOverFarVsTime+"]").c_str());
07777 cNormNearOverFarVsTime->Print((sNormNearOverFarVsTime+"]").c_str());
07778
07779 cPinVsTime->Print((sPinVsTime+"]").c_str());
07780 cNormPinVsTime->Print((sNormPinVsTime+"]").c_str());
07781 cNormPinVsTimeZoom->Print((sNormPinVsTimeZoom+"]").c_str());
07782 cPinErrorVsTime->Print((sPinErrorVsTime+"]").c_str());
07783 cPinNumEntVsTime->Print((sPinNumEntVsTime+"]").c_str());
07784
07785 MSG("LIPlexMaps",Msg::kInfo)
07786 <<endl<<" ** Finished the DriftWithTime method... ** "<<endl;
07787 }
07788
07789
07790
07791 void LIPlexMaps::SetGraphAxisEtc(TGraph* g,Int_t startTimeSecs,
07792 Int_t endTimeSecs)
07793 {
07794 MSG("LIPlexMaps",Msg::kVerbose)
07795 <<endl<<" ** Running the SetGraphAxisEtc method... ** "<<endl;
07796
07797 TDatime startDatime;
07798 startDatime.Set(startTimeSecs);
07799
07800 TDatime endDatime;
07801 endDatime.Set(endTimeSecs);
07802
07803
07804 string sStartHour=Form("%d",startDatime.GetHour());
07805 string sStartMinute=Form("%d",startDatime.GetMinute());
07806 string sStartSecond=Form("%d",startDatime.GetSecond());
07807 string sStartYear=Form("%d",startDatime.GetYear());
07808 string sStartMonth=Form("%d",startDatime.GetMonth());
07809 string sStartDay=Form("%d",startDatime.GetDay());
07810 if (startDatime.GetHour()<10) sStartHour="0"+sStartHour;
07811 if (startDatime.GetMinute()<10) sStartMinute="0"+sStartMinute;
07812 if (startDatime.GetSecond()<10) sStartSecond="0"+sStartSecond;
07813 if (startDatime.GetMonth()<10) sStartMonth="0"+sStartMonth;
07814 if (startDatime.GetDay()<10) sStartDay="0"+sStartDay;
07815
07816
07817 string sEndHour=Form("%d",endDatime.GetHour());
07818 string sEndMinute=Form("%d",endDatime.GetMinute());
07819 string sEndSecond=Form("%d",endDatime.GetSecond());
07820 string sEndYear=Form("%d",endDatime.GetYear());
07821 string sEndMonth=Form("%d",endDatime.GetMonth());
07822 string sEndDay=Form("%d",endDatime.GetDay());
07823 if (endDatime.GetHour()<10) sEndHour="0"+sEndHour;
07824 if (endDatime.GetMinute()<10) sEndMinute="0"+sEndMinute;
07825 if (endDatime.GetSecond()<10) sEndSecond="0"+sEndSecond;
07826 if (endDatime.GetMonth()<10) sEndMonth="0"+sEndMonth;
07827 if (endDatime.GetDay()<10) sEndDay="0"+sEndDay;
07828
07829 static Bool_t firstTime=true;
07830 if (firstTime){
07831 MSG("LIAnalysis",Msg::kInfo)
07832 <<"Setting graph axis info:"<<endl;
07833 MSG("LIAnalysis",Msg::kInfo)
07834 <<" Start time "<<sStartHour
07835 <<":"<<sStartMinute
07836 <<":"<<sStartSecond
07837 <<" on "<<startDatime.GetYear()
07838 <<"/"<<sStartMonth
07839 <<"/"<<sStartDay
07840 <<endl;
07841
07842 MSG("LIAnalysis",Msg::kInfo)
07843 <<" End time "<<sEndHour
07844 <<":"<<sEndMinute
07845 <<":"<<sEndSecond
07846 <<" on "<<endDatime.GetYear()
07847 <<"/"<<sEndMonth
07848 <<"/"<<sEndDay
07849 <<endl;
07850 }
07851 firstTime=false;
07852
07853 Int_t timeRange=endTimeSecs-startTimeSecs;
07854
07855
07856 if (g){
07857 if (sStartDay==sEndDay && timeRange<1*24*60*60){
07858 string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay+")";
07859 g->GetXaxis()->SetTitle(title.c_str());
07860 g->GetXaxis()->SetTimeFormat("%H:%M");
07861 }
07862 else if (timeRange>1*24*60*60 && timeRange<2*24*60*60){
07863 string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
07864 +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
07865 g->GetXaxis()->SetTitle(title.c_str());
07866 g->GetXaxis()->SetTimeFormat("%H:%M");
07867 }
07868 else if (timeRange>2*24*60*60 && timeRange<5*24*60*60){
07869 string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
07870 +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
07871 g->GetXaxis()->SetTitle(title.c_str());
07872 g->GetXaxis()->SetTimeFormat("%H:%M-%d/%m");
07873 }
07874 else{
07875 string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
07876 +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
07877 g->GetXaxis()->SetTitle(title.c_str());
07878 g->GetXaxis()->SetTimeFormat("%H:%M-%d/%m");
07879
07880 g->GetXaxis()->SetNdivisions(506);
07881
07882
07883
07884
07885 }
07886
07887
07888 g->GetXaxis()->SetTimeDisplay(1);
07889 g->GetXaxis()->CenterTitle();
07890
07891
07892 g->SetMarkerStyle(3);
07893 g->SetMarkerColor(2);
07894 g->SetMarkerSize(0.35);
07895 g->SetLineColor(46);
07896 }
07897 else{
07898 MSG("LIPlexMaps",Msg::kError)
07899 <<"Input graph pointer is null!"
07900 <<" Will do nothing."<<endl;
07901 }
07902
07903 MSG("LIPlexMaps",Msg::kVerbose)
07904 <<endl<<" ** Finished the SetGraphAxisEtc method... **"<<endl;
07905 }
07906
07907
07908
07909 void LIPlexMaps::ReadDbPulserRawGain()
07910 {
07911 MSG("LIPlexMaps",Msg::kInfo)
07912 <<endl<<" ** Running the ReadDbPulserRawGain() method... ** "<<endl;
07913
07914
07915
07916 Int_t detectorType=4;
07917
07918 Int_t* planeMax=new Int_t[NUMCRATES];
07919 Int_t* planeMin=new Int_t[NUMCRATES];
07920 fLookup.SetPbPlanes(planeMin,planeMax,detectorType);
07921
07922 const Int_t firstStripBin=FIRSTSTRIP-8;
07923 const Int_t lastStripBin=LASTSTRIP+9;
07924 const Int_t bins=lastStripBin-firstStripBin;
07925
07926 string sConstantBit="";
07927
07928 MSG("LIAnalysis",Msg::kInfo)
07929 <<"sConstantBit="<<sConstantBit<<endl;
07930
07931 Int_t mycrates=5;
07932
07933 TH2F **hStripVsPlaneGain=0;
07934 hStripVsPlaneGain= new TH2F*[mycrates];
07935 for (Int_t i=0;i<NUMCRATES;i++){
07936 string sPb=Form("%d",i);
07937 fS="Gain (Crate "+sPb+")";
07938 hStripVsPlaneGain[i]=new TH2F(fS.c_str(),fS.c_str(),
07939 planeMax[i]-planeMin[i],
07940 planeMin[i],planeMax[i],
07941 bins,firstStripBin,lastStripBin);
07942 hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
07943 hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
07944 hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
07945 hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
07946 hStripVsPlaneGain[i]->SetFillColor(0);
07947
07948 }
07949
07950 TH2F **hStripVsPlaneError=0;
07951 hStripVsPlaneError= new TH2F*[NUMCRATES];
07952 for (Int_t i=0;i<NUMCRATES;i++){
07953 string sPb=Form("%d",i);
07954 fS="Gain Error (Crate "+sPb+")";
07955 hStripVsPlaneError[i]=new TH2F(fS.c_str(),fS.c_str(),
07956 planeMax[i]-planeMin[i],
07957 planeMin[i],planeMax[i],
07958 bins,firstStripBin,lastStripBin);
07959 hStripVsPlaneError[i]->GetXaxis()->SetTitle("Plane");
07960 hStripVsPlaneError[i]->GetXaxis()->CenterTitle();
07961 hStripVsPlaneError[i]->GetYaxis()->SetTitle("Strip");
07962 hStripVsPlaneError[i]->GetYaxis()->CenterTitle();
07963 hStripVsPlaneError[i]->SetFillColor(0);
07964
07965 }
07966
07967 TH2F **hStripVsPlaneNumEntries=0;
07968 hStripVsPlaneNumEntries= new TH2F*[NUMCRATES];
07969 for (Int_t i=0;i<NUMCRATES;i++){
07970 string sPb=Form("%d",i);
07971 fS="NumEntries_Crate"+sPb;
07972 hStripVsPlaneNumEntries[i]=new TH2F(fS.c_str(),fS.c_str(),
07973 planeMax[i]-planeMin[i],
07974 planeMin[i],planeMax[i],
07975 bins,firstStripBin,lastStripBin);
07976 hStripVsPlaneNumEntries[i]->GetXaxis()->SetTitle("Plane");
07977 hStripVsPlaneNumEntries[i]->GetXaxis()->CenterTitle();
07978 hStripVsPlaneNumEntries[i]->GetYaxis()->SetTitle("Strip");
07979 hStripVsPlaneNumEntries[i]->GetYaxis()->CenterTitle();
07980 hStripVsPlaneNumEntries[i]->SetFillColor(0);
07981
07982 }
07983
07984 Detector::Detector_t det=Detector::kCalDet;
07985
07986 VldTimeStamp tsNow;
07987 VldContext vldNow(det,SimFlag::kData,tsNow);
07988
07989 DbiResultPtr<PulserRawGain> dbiPulserRawGain;
07990
07991 UInt_t numRows=dbiPulserRawGain.NewQuery(vldNow,0);
07992
07993 MSG("LIPlexMaps",Msg::kInfo)
07994 <<"New DB query produced "<<numRows<<" rows"<<endl;
07995
07997
07999 for(UInt_t i=0;i<numRows;i++) {
08000 const PulserRawGain* pulserRawGain=dbiPulserRawGain.GetRow(i);
08001
08002 Float_t gain=*pulserRawGain->GetMean();
08003 Float_t error=*pulserRawGain->GetError();
08004 Float_t numEntries=*pulserRawGain->GetNumEntries();
08005
08006 UInt_t seidkey=pulserRawGain->GetStripEnd();
08007 Int_t plane=-1;
08008 Int_t strip=-1;
08009 Int_t end=-1;
08010 fLookup.UnencodePlnStripEndKey(seidkey,det,plane,strip,end);
08011
08012 hStripVsPlaneGain[end-1]->Fill(plane,strip,gain);
08013 hStripVsPlaneError[end-1]->Fill(plane,strip,error);
08014 hStripVsPlaneNumEntries[end-1]->Fill(plane,strip,numEntries);
08015
08016 MSG("LIPlexMaps",Msg::kInfo)
08017 <<"("<<plane<<";"<<strip<<";"<<end<<")"
08018 <<" gain="<<gain<<", error="<<error<<", numEnt="<<numEntries
08019 <<", seidkey="<<seidkey<<endl;
08020 }
08022
08024
08025
08026 gStyle->SetOptStat(0);
08027
08028 TCanvas *cStripVsPlaneGain=new TCanvas
08029 ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);
08030 cStripVsPlaneGain->SetFillColor(0);
08031 cStripVsPlaneGain->Divide(1,2);
08032 cStripVsPlaneGain->cd(1);
08033 hStripVsPlaneGain[0]->Draw("colz");
08034 cStripVsPlaneGain->cd(2);
08035 hStripVsPlaneGain[1]->Draw("colz");
08036
08037 TCanvas *cStripVsPlaneError=new TCanvas
08038 ("cStripVsPlaneError","StripVsPlane: Error",0,0,1000,800);
08039 cStripVsPlaneError->SetFillColor(0);
08040 cStripVsPlaneError->Divide(1,2);
08041 cStripVsPlaneError->cd(1);
08042 hStripVsPlaneError[0]->Draw("colz");
08043 cStripVsPlaneError->cd(2);
08044 hStripVsPlaneError[1]->Draw("colz");
08045
08046 TCanvas *cStripVsPlaneNumEntries=new TCanvas
08047 ("cStripVsPlaneNumEntries","StripVsPlane: NumEntries",
08048 0,0,1000,800);
08049 cStripVsPlaneNumEntries->SetFillColor(0);
08050 cStripVsPlaneNumEntries->Divide(1,2);
08051 cStripVsPlaneNumEntries->cd(1);
08052 hStripVsPlaneNumEntries[0]->Draw("colz");
08053 cStripVsPlaneNumEntries->cd(2);
08054 hStripVsPlaneNumEntries[1]->Draw("colz");
08055
08056 MSG("LIPlexMaps",Msg::kInfo)
08057 <<endl<<" ** Finished the ReadDbPulserRawGain() method... **"<<endl;
08058 }
08059
08060
08061
08062 void LIPlexMaps::RatioRawToRefDrift()
08063 {
08064 MSG("LIPlexMaps",Msg::kInfo)
08065 <<endl<<" ** Running the RatioRawToRefDrift() method... ** "<<endl;
08066
08067
08068
08069 Int_t detectorType=4;
08070
08071 Int_t* planeMax=new Int_t[NUMCRATES];
08072 Int_t* planeMin=new Int_t[NUMCRATES];
08073 fLookup.SetPbPlanes(planeMin,planeMax,detectorType);
08074
08075 const Int_t firstStripBin=FIRSTSTRIP-8;
08076 const Int_t lastStripBin=LASTSTRIP+9;
08077 const Int_t bins=lastStripBin-firstStripBin;
08078
08079 string sConstantBit="";
08080
08081 MSG("LIAnalysis",Msg::kInfo)
08082 <<"sConstantBit="<<sConstantBit<<endl;
08083
08084 TH2F **hStripVsPlaneRawToRef=0;
08085 hStripVsPlaneRawToRef= new TH2F*[NUMCRATES];
08086 for (Int_t i=0;i<NUMCRATES;i++){
08087 string sPb=Form("%d",i);
08088 fS="RawToRef (Crate "+sPb+")";
08089 hStripVsPlaneRawToRef[i]=new TH2F(fS.c_str(),fS.c_str(),
08090 planeMax[i]-planeMin[i],
08091 planeMin[i],planeMax[i],
08092 bins,firstStripBin,lastStripBin);
08093 hStripVsPlaneRawToRef[i]->GetXaxis()->SetTitle("Plane");
08094 hStripVsPlaneRawToRef[i]->GetXaxis()->CenterTitle();
08095 hStripVsPlaneRawToRef[i]->GetYaxis()->SetTitle("Strip");
08096 hStripVsPlaneRawToRef[i]->GetYaxis()->CenterTitle();
08097 hStripVsPlaneRawToRef[i]->SetFillColor(0);
08098
08099 }
08100
08101 Detector::Detector_t det=Detector::kCalDet;
08102 VldTimeStamp tsNow;
08103 VldContext vldNow(det,SimFlag::kData,tsNow);
08104
08105 DbiResultPtr<PulserRawDrift> dbiPulserRawDrift;
08106 DbiResultPtr<PulserRefDrift> dbiPulserRefDrift;
08107
08108 UInt_t numRowsRaw=dbiPulserRawDrift.NewQuery(vldNow,0);
08109 UInt_t numRowsRef=dbiPulserRefDrift.NewQuery(vldNow,0);
08110
08111 if (numRowsRef!=numRowsRaw) {
08112 MSG("LIPlexMaps",Msg::kError)
08113 <<"Raw and Ref PulserDrift tables are different sizes"<<endl;
08114
08115
08116 }
08117
08118 UInt_t numRows=numRowsRaw;
08119 if (numRowsRaw>numRowsRef) numRows=numRowsRef;
08120
08121 MSG("LIPlexMaps",Msg::kInfo)
08122 <<"Using "<<numRows<<" rows"<<endl;
08123
08124 map<Int_t,PulserRawDrift> rawDrift;
08125 map<Int_t,PulserRefDrift> refDrift;
08126
08128
08130 for(UInt_t i=0;i<numRows;i++) {
08131 const PulserRawDrift* pulserRawDrift=dbiPulserRawDrift.GetRow(i);
08132 const PulserRefDrift* pulserRefDrift=dbiPulserRefDrift.GetRow(i);
08133
08134
08135 rawDrift[pulserRawDrift->GetStripEnd()]=*pulserRawDrift;
08136 refDrift[pulserRefDrift->GetStripEnd()]=*pulserRefDrift;
08137 }
08139
08141
08142 MSG("LIPlexMaps",Msg::kInfo)
08143 <<"Finished loop"<<endl;
08144
08145 map<Int_t,PulserRawDrift>::iterator raw=rawDrift.begin();
08146 map<Int_t,PulserRefDrift>::iterator ref=refDrift.begin();
08147
08148
08149 while(raw!=rawDrift.end()){
08150
08151 Float_t meanRaw=raw->second.GetMean();
08152 Float_t errorRaw=raw->second.GetError();
08153 Float_t numEntriesRaw=raw->second.GetNumEntries();
08154 UInt_t seidkeyRaw=raw->first;
08155 Int_t planeRaw=-1;
08156 Int_t stripRaw=-1;
08157 Int_t endRaw=-1;
08158 fLookup.UnencodePlnStripEndKey(seidkeyRaw,det,planeRaw,stripRaw,
08159 endRaw);
08160
08161 Float_t meanRef=ref->second.GetMean();
08162 Float_t errorRef=ref->second.GetError();
08163 Float_t numEntriesRef=ref->second.GetNumEntries();
08164 UInt_t seidkeyRef=ref->first;
08165 Int_t planeRef=-1;
08166 Int_t stripRef=-1;
08167 Int_t endRef=-1;
08168 fLookup.UnencodePlnStripEndKey(seidkeyRef,det,planeRef,stripRef,
08169 endRef);
08170
08171
08172 if (seidkeyRef!=seidkeyRaw){
08173 MSG("LIPlexMaps",Msg::kError)
08174 <<"Raw and Ref seidkeys are different"<<endl;
08175
08176
08177 raw++;
08178 ref++;
08179 continue;
08180 }
08181
08182
08183 if (meanRef>0){
08184 hStripVsPlaneRawToRef[endRef-1]->Fill(planeRef,stripRef,
08185 meanRaw/meanRef);
08186 }
08187
08188
08189 string sMeanRaw=Form("%.1f",meanRaw);
08190 string sErrorRaw=Form("%.2f",errorRaw);
08191 string sNumEntriesRaw=Form("%.0f",numEntriesRaw);
08192 string sSeIdRaw=Form("%.1f",seidkeyRaw);
08193
08194 string sMeanRef=Form("%.1f",meanRef);
08195 string sErrorRef=Form("%.2f",errorRef);
08196 string sNumEntriesRef=Form("%.0f",numEntriesRef);
08197 string sSeIdRef=Form("%.1f",seidkeyRef);
08198
08199 string sMeanDif=Form("%.1f",meanRef-meanRaw);
08200 string sErrorDif=Form("%.2f",errorRef-errorRaw);
08201 string sNumEntriesDif=Form("%.0f",numEntriesRef-numEntriesRaw);
08202 string sSeIdDiff=Form("%.1f",seidkeyRef-seidkeyRaw);
08203
08204 MSG("LIPlexMaps",Msg::kInfo)
08205 <<endl
08206 <<"Ref (m,er,num,seid)=("<<sMeanRef<<";"<<sErrorRef
08207 <<";"<<sNumEntriesRef<<";"<<sSeIdRef<<")"
08208 <<endl
08209 <<"Raw (m,er,num,seid)=("<<sMeanRaw<<";"<<sErrorRaw
08210 <<";"<<sNumEntriesRaw<<";"<<sSeIdRaw<<")"
08211 <<endl
08212 <<"Diff (m,er,num,seid)=("<<sMeanDif<<";"<<sErrorDif
08213 <<";"<<sNumEntriesDif<<";"<<sSeIdDiff<<")"
08214 <<endl;
08215
08216 raw++;
08217 ref++;
08218 }
08219
08220
08221 gStyle->SetOptStat(0);
08222
08223 TCanvas *cStripVsPlaneRawToRef=new TCanvas
08224 ("cStripVsPlaneRawToRef","StripVsPlane: RawToRef",0,0,1000,800);
08225 cStripVsPlaneRawToRef->SetFillColor(0);
08226 cStripVsPlaneRawToRef->Divide(1,2);
08227 cStripVsPlaneRawToRef->cd(1);
08228 hStripVsPlaneRawToRef[0]->Draw("colz");
08229 cStripVsPlaneRawToRef->cd(2);
08230 hStripVsPlaneRawToRef[1]->Draw("colz");
08231
08232 MSG("LIPlexMaps",Msg::kInfo)
08233 <<endl<<" ** Finished the RatioRawToRefDrift() method... ** "
08234 <<endl;
08235 }
08236
08237
08238
08239
08240 map<Int_t,Float_t> LIPlexMaps::GetRawPinMap(VldContext vldCtx)
08241 {
08242 MSG("LIPlexMaps",Msg::kDebug)
08243 <<endl<<" ** Running the GetRawPinMap method... **"<<endl;
08244
08245 Detector::Detector_t det=Detector::kCalDet;
08246 StripEnd::EStripEnd stripEndType = StripEnd::kUnknown;
08247
08248 PlexHandle *plexHandle=new PlexHandle(vldCtx);
08249
08250 DbiResultPtr<PulserRawDriftPin> driftRawPin;
08251 UInt_t numRowsPin=driftRawPin.NewQuery(vldCtx,0);
08252
08253 if (numRowsPin!=static_cast<UInt_t>(NUMLEDS*NUMPULSERBOXES*2)){
08254 MSG("LIPlexMaps",Msg::kWarning)
08255 <<"PulserRawDriftPin only contains "<<numRowsPin<<" rows"<<endl;
08256 }
08257 map<Int_t,Float_t> pinAdc;
08258
08259 Int_t mapEntCounter=0;
08260
08262
08264 for(UInt_t i=0;i<numRowsPin;i++) {
08265
08266
08267 const PulserRawDriftPin* rawPin=driftRawPin.GetRow(i);
08268
08269 PlexLedId ledId=plexHandle->GetLedId(rawPin->GetPinDiodeId());
08270
08271 pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
08272 GetPinDiodeIds(ledId);
08273
08274
08275 if (rawPin->GetPinDiodeId()==plexPins.second) continue;
08276
08277 MSG("LIPlexMaps",Msg::kDebug)
08278 <<"Got high gain pin:"<<endl;
08279 if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)){
08280 rawPin->GetPinDiodeId().Print();
08281 }
08282
08283 for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
08284 for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
08285 for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
08286
08287 if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
08288 else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
08289
08290 PlexStripEndId stripEndId(det,pl,st,stripEndType);
08291
08292 PlexLedId currentSELedId=plexHandle->GetLedId(stripEndId);
08293
08294 if (currentSELedId==ledId){
08295 pinAdc[stripEndId.BuildPlnStripEndKey()]=rawPin->GetMean();
08296
08297 MSG("LIPlexMaps",Msg::kVerbose)
08298 <<"Filling map, mean="<<rawPin->GetMean()<<endl;
08299 mapEntCounter++;
08300 }
08301 }
08302 }
08303 }
08304 }
08305
08306 if (mapEntCounter!=NUMPLANES*NUMSTRIPS*NUMENDS){
08307 MSG("LIPlexMaps",Msg::kWarning)
08308 <<"Only "<<mapEntCounter<<" entries added to pin map"<<endl;
08309 }
08310
08311 MSG("LIPlexMaps",Msg::kDebug)
08312 <<endl<<" ** Finished the GetRawPinMap method... ** "<<endl;
08313 return pinAdc;
08314 }
08315
08316
08317
08318
08319
08320
08321
08322
08323
08324
08325
08326
08327
08328
08329
08330
08331
08332
08333
08334
08335
08337
08339
08340
08341
08342
08343
08344
08345
08346
08347
08348
08349
08350
08351
08352
08353
08355
08357
08358
08359
08360
08361
08362
08363
08364
08365 map<PlexLedId,LIPulserPin> LIPlexMaps::GetRawPinLedMap
08366 (VldContext vldCtx)
08367 {
08368 MSG("LIPlexMaps",Msg::kDebug)
08369 <<endl<<" ** Running the GetRawPinLedMap method... **"<<endl;
08370
08371 PlexHandle *plexHandle=new PlexHandle(vldCtx);
08372
08373 DbiResultPtr<PulserRawDriftPin> driftRawPin;
08374 UInt_t numRowsPin=driftRawPin.NewQuery(vldCtx,0);
08375
08376 if (static_cast<Int_t>(numRowsPin)!=NUMLEDS*NUMPULSERBOXES*2){
08377 MSG("LIPlexMaps",Msg::kWarning)
08378 <<"PulserRawDriftPin only contains "<<numRowsPin<<" rows"
08379 <<", expected "<<NUMLEDS*NUMPULSERBOXES*2<<endl;
08380 }
08381
08382 map<PlexLedId,Float_t> pinAdc;
08383 map<PlexLedId,LIPulserPin> pinAdcOb;
08384
08385 Int_t mapEntCounter=0;
08386
08388
08390 for(UInt_t i=0;i<numRowsPin;i++) {
08391
08392
08393 const PulserRawDriftPin* rawPin=driftRawPin.GetRow(i);
08394
08395 PlexLedId ledId=plexHandle->GetLedId(rawPin->GetPinDiodeId());
08396
08397 pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
08398 GetPinDiodeIds(ledId);
08399
08400
08401
08402
08403
08404 if (rawPin->GetPinDiodeId()==plexPins.first) continue;
08405
08406 MSG("LIPlexMaps",Msg::kDebug)
08407 <<"Got high gain pin:"<<endl;
08408 if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)){
08409 rawPin->GetPinDiodeId().Print();
08410 }
08411
08412
08413 pinAdc[ledId]=rawPin->GetMean();
08414
08415 MSG("LIPlexMaps",Msg::kDebug)
08416 <<"Added pin mean="<<rawPin->GetMean()<<endl;
08417
08418 pinAdcOb[ledId].mean=rawPin->GetMean();
08419 pinAdcOb[ledId].error=rawPin->GetError();
08420 pinAdcOb[ledId].numEnt=rawPin->GetNumEntries();
08421
08422 if (rawPin->GetMean()<=0){
08423 MSG("LIPlexMaps",Msg::kInfo)
08424 <<"Warning bad pin="<<rawPin->GetMean()<<" (PB:LED)=("
08425 <<ledId.GetPulserBox()<<":"<<ledId.GetLedInBox()<<")"<<endl;
08426 }
08427
08428
08429 mapEntCounter++;
08430 }
08431
08432
08433 if (mapEntCounter!=NUMLEDS){
08434 MSG("LIPlexMaps",Msg::kWarning)
08435 <<"Only "<<mapEntCounter<<" entries added to pin map"<<endl;
08436 }
08437
08438 MSG("LIPlexMaps",Msg::kDebug)
08439 <<endl<<" ** Finished the GetRawPinLedMap method... ** "<<endl;
08440 return pinAdcOb;
08441 }
08442
08443
08444
08445 map<Int_t,LIPulserPin> LIPlexMaps::GetRefAdcPinRatio(VldContext vldCtx)
08446 {
08447 MSG("LIPlexMaps",Msg::kDebug)
08448 <<endl<<" ** Running the GetRefAdcPinRatio method... **"<<endl;
08449
08450 map<Int_t,LIPulserPin> pinAdc;
08451
08452 Detector::Detector_t det=vldCtx.GetDetector();
08453 StripEnd::EStripEnd stripEndType = StripEnd::kUnknown;
08454
08455 PlexHandle *plexHandle=new PlexHandle(vldCtx);
08456
08457 DbiResultPtr<PulserRefDriftPin> driftRefPin;
08458 UInt_t numRowsPin=driftRefPin.NewQuery(vldCtx,0);
08459
08460 DbiResultPtr<PulserRefDrift> dbiPulserRefDrift;
08461 UInt_t numRowsDrift=dbiPulserRefDrift.NewQuery(vldCtx,0);
08462
08463 static string sVldRange=dbiPulserRefDrift.GetValidityRec()->
08464 GetVldRange().AsString();
08465 static Bool_t firstTime=true;
08466
08467 if (sVldRange==dbiPulserRefDrift.GetValidityRec()->
08468 GetVldRange().AsString() && !firstTime){
08469 return pinAdc;
08470 }
08471
08472 MSG("LIPlexMaps",Msg::kInfo)
08473 <<endl<<"Running the GetRefAdcPinRatio method..."<<endl;
08474
08475
08476 firstTime=false;
08477 sVldRange=dbiPulserRefDrift.GetValidityRec()->
08478 GetVldRange().AsString();
08479
08480 MSG("LIPlexMaps",Msg::kInfo)
08481 <<"PulserRefDrift contains "<<numRowsDrift<<" rows"<<endl
08482 <<"PulserRefDriftPin contains "<<numRowsPin<<" rows"<<endl;
08483
08484 Int_t mapEntCounter=0;
08485
08487
08489 for(UInt_t i=0;i<numRowsPin;i++) {
08490
08491
08492 const PulserRefDriftPin* refPin=driftRefPin.GetRow(i);
08493
08494 PlexLedId ledId=plexHandle->GetLedId(refPin->GetPinDiodeId());
08495
08496 pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
08497 GetPinDiodeIds(ledId);
08498
08499
08500 if (refPin->GetPinDiodeId()==plexPins.second) continue;
08501
08502 MSG("LIPlexMaps",Msg::kDebug)
08503 <<"Got high gain pin:"<<endl;
08504 if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)){
08505 refPin->GetPinDiodeId().Print();
08506 }
08507
08508 for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
08509 for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
08510 for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
08511
08512 if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
08513 else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
08514
08515 PlexStripEndId stripEndId(det,pl,st,stripEndType);
08516
08517 if (!this->IsScintStrip(stripEndId,plexHandle)) continue;
08518
08519 PlexLedId currentSELedId=plexHandle->GetLedId(stripEndId);
08520
08521 if (currentSELedId==ledId){
08522 pinAdc[stripEndId.BuildPlnStripEndKey()].mean=refPin->
08523 GetMean();
08524 pinAdc[stripEndId.BuildPlnStripEndKey()].error=refPin->
08525 GetError();
08526 pinAdc[stripEndId.BuildPlnStripEndKey()].numEnt=refPin->
08527 GetNumEntries();
08528
08529 MSG("LIPlexMaps",Msg::kDebug)
08530 <<"Filling map; mean="<<refPin->GetMean()<<endl;
08531 mapEntCounter++;
08532 }
08533 }
08534 }
08535 }
08536 }
08537 MSG("LIPlexMaps",Msg::kInfo)
08538 <<"Total entries added to pin map = "<<mapEntCounter<<endl;
08539
08540
08541 map<Int_t,LIPulserPin> adcPinRatio;
08542
08543
08544 for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
08545 for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
08546 for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
08547
08548 if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
08549 else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
08550
08551 PlexStripEndId stripEndId(det,pl,st,stripEndType);
08552
08553 adcPinRatio[stripEndId.BuildPlnStripEndKey()].mean=-1;
08554 adcPinRatio[stripEndId.BuildPlnStripEndKey()].error=-1;
08555 adcPinRatio[stripEndId.BuildPlnStripEndKey()].numEnt=-1;
08556
08557 }
08558 }
08559 }
08560
08562
08564 for(UInt_t i=0;i<numRowsDrift;i++) {
08565
08566 const PulserRefDrift* pulserRefDrift=dbiPulserRefDrift.GetRow(i);
08567
08568 UInt_t seidkey=pulserRefDrift->GetStripEnd();
08569
08570
08571 adcPinRatio[seidkey].mean=pulserRefDrift->GetMean();
08572 adcPinRatio[seidkey].error=pulserRefDrift->GetError();
08573 adcPinRatio[seidkey].numEnt=pulserRefDrift->GetNumEntries();
08574
08575
08576 if (pinAdc[seidkey].mean>0){
08577 adcPinRatio[seidkey].mean/=pinAdc[seidkey].mean;
08578
08579
08580 adcPinRatio[seidkey].error/=pulserRefDrift->GetMean();
08581
08582 MSG("LIPlexMaps",Msg::kDebug)
08583 <<"Filling ratio map="<<adcPinRatio[seidkey].mean
08584 <<" (+/- "<<adcPinRatio[seidkey].error*100<<"%)"<<endl;
08585 }
08586 else {
08587 MSG("LIPlexMaps",Msg::kWarning)
08588 <<"Reference pin has zero mean!"<<endl;
08589 }
08590 }
08592
08594
08595 MSG("LIPlexMaps",Msg::kDebug)
08596 <<endl<<" ** Finished the GetRefAdcPinRatio method... ** "<<endl;
08597 return adcPinRatio;
08598 }
08599
08600
08601
08602 Bool_t LIPlexMaps::IsScintStrip(PlexStripEndId& stripEndId,
08603 PlexHandle* plexHandle)
08604 {
08605 MSG("LIPlexMaps",Msg::kVerbose)
08606 <<" ** Running the IsScintStrip method... **"<<endl;
08607
08608
08609 RawChannelId tempRawChId=plexHandle->GetRawChannelId(stripEndId);
08610
08611
08612 if (plexHandle->GetReadoutType(tempRawChId)!=
08613 ReadoutType::kScintStrip){
08614
08615 MSG("LIPlexMaps",Msg::kVerbose)
08616 <<"Ignoring ReadoutType="<<ReadoutType::AsString
08617 (plexHandle->GetReadoutType(tempRawChId))
08618 <<endl;
08619 return false;
08620 }
08621
08622 MSG("LIPlexMaps",Msg::kVerbose)
08623 <<" ** Finished IsScintStrip method... ** "<<endl;
08624 return true;
08625 }
08626
08627
08628
08629 void LIPlexMaps::ReadDbPulserDriftPin()
08630 {
08631 MSG("LIPlexMaps",Msg::kInfo)
08632 <<endl<<" ** Running the ReadDbPulserDriftPin() method... **"<<endl;
08633
08634
08635
08636 VldTimeStamp tsNow;
08637 VldContext vldNow(Detector::kCalDet,SimFlag::kData,tsNow);
08638 PlexHandle *plexHandle=new PlexHandle(vldNow);
08639
08640 DbiResultPtr<PulserRawDriftPin> driftRawPin;
08641 DbiResultPtr<PulserRefDriftPin> driftRefPin;
08642
08643
08644 UInt_t numRows=driftRawPin.NewQuery(vldNow,0);
08645 driftRefPin.NewQuery(vldNow,0);
08646
08647 MSG("LIPlexMaps",Msg::kInfo)
08648 <<"New DB query produced "<<numRows<<" rows"<<endl;
08649
08650 map<Int_t,PulserRawDriftPin> rawPin;
08651 map<Int_t,PulserRefDriftPin> refPin;
08652
08654
08656 for(UInt_t i=0;i<numRows;i++) {
08657
08658
08659
08660 Int_t chAddRaw=plexHandle->GetRawChannelId
08661 (driftRawPin.GetRow(i)->GetPinDiodeId()).GetChAdd();
08662 Int_t chAddRef=plexHandle->GetRawChannelId
08663 (driftRefPin.GetRow(i)->GetPinDiodeId()).GetChAdd();
08664
08665 rawPin[chAddRaw]=*driftRawPin.GetRow(i);
08666 refPin[chAddRef]=*driftRefPin.GetRow(i);
08667 }
08669
08671
08672 MSG("LIPlexMaps",Msg::kInfo)
08673 <<"Finished loop"<<endl;
08674
08675 map<Int_t,PulserRawDriftPin>::iterator raw=rawPin.begin();
08676 map<Int_t,PulserRefDriftPin>::iterator ref=refPin.begin();
08677
08678 while(raw!=rawPin.end()){
08679
08680 Float_t meanRaw=raw->second.GetMean();
08681 Float_t errorRaw=raw->second.GetError();
08682 Float_t numEntriesRaw=raw->second.GetNumEntries();
08683 Int_t chAddRaw=plexHandle->GetRawChannelId
08684 (raw->second.GetPinDiodeId()).GetChAdd();
08685
08686 Float_t meanRef=ref->second.GetMean();
08687 Float_t errorRef=ref->second.GetError();
08688 Float_t numEntriesRef=ref->second.GetNumEntries();
08689 Int_t chAddRef=plexHandle->GetRawChannelId
08690 (ref->second.GetPinDiodeId()).GetChAdd();
08691
08692 string sMeanRaw=Form("%.1f",meanRaw);
08693 string sErrorRaw=Form("%.2f",errorRaw);
08694 string sNumEntriesRaw=Form("%.0f",numEntriesRaw);
08695 string sChAddRaw=Form("%d",chAddRaw);
08696
08697 string sMeanRef=Form("%.1f",meanRef);
08698 string sErrorRef=Form("%.2f",errorRef);
08699 string sNumEntriesRef=Form("%.0f",numEntriesRef);
08700 string sChAddRef=Form("%d",chAddRef);
08701
08702 string sMeanDif=Form("%.1f",meanRef-meanRaw);
08703 string sErrorDif=Form("%.2f",errorRef-errorRaw);
08704 string sNumEntriesDif=Form("%.0f",numEntriesRef-numEntriesRaw);
08705 string sChAddDif=Form("%d",chAddRef-chAddRaw);
08706
08707 MSG("LIPlexMaps",Msg::kInfo)
08708 <<endl
08709 <<"Ref (m,er,num,ch)=("<<sMeanRef<<";"<<sErrorRef
08710 <<";"<<sNumEntriesRef<<";"<<sChAddRef<<")"
08711 <<endl
08712 <<"Raw (m,er,num,ch)=("<<sMeanRaw<<";"<<sErrorRaw
08713 <<";"<<sNumEntriesRaw<<";"<<sChAddRaw<<")"
08714 <<endl
08715 <<"Diff (m,er,num,ch)=("<<sMeanDif<<";"<<sErrorDif
08716 <<";"<<sNumEntriesDif<<";"<<sChAddDif<<")"
08717 <<endl;
08718
08719 raw++;
08720 ref++;
08721 }
08722
08723
08724 MSG("LIPlexMaps",Msg::kInfo)
08725 <<endl<<" ** Finished the ReadDbPulserDriftPin() method... ** "
08726 <<endl;
08727 }
08728
08729
08730
08731
08732 std::map<Int_t,Double_t> LIPlexMaps::GetGainMap(Detector::Detector_t det, VldTimeStamp ts)
08733 {
08734 std::map<Int_t,Double_t> gainmap;
08735
08736
08737 VldContext vldCtx(det, SimFlag::kData, ts);
08738
08739 DbiResultPtr<CalADCtoPEs> dbiCalADCtoPEs;
08740
08741
08742 Int_t task = 0;
08743 if (det == Detector::kNear) task = 1;
08744
08745
08746 UInt_t numRows = dbiCalADCtoPEs.NewQuery(vldCtx,task);
08747
08748
08749
08750
08751
08752
08753
08754
08755 for (UInt_t i = 0; i < numRows; ++i)
08756 {
08757 const CalADCtoPEs* calAdcToPe = dbiCalADCtoPEs.GetRow(i);
08758 Float_t gain = calAdcToPe->GetGain();
08759 UInt_t seid = calAdcToPe->GetSEIDkey();
08760
08761 gainmap[seid] = gain;
08762 }
08763
08764 return gainmap;
08765 }
08766
08767 TH1D LIPlexMaps::GainDifference(Detector::Detector_t det, VldTimeStamp first, VldTimeStamp second)
08768 {
08769
08770 LIPlexMaps LIPlex;
08771
08772
08773 std::map<Int_t,Double_t> pt1 = LIPlex.GetGainMap(det, first);
08774 std::map<Int_t,Double_t> pt2 = LIPlex.GetGainMap(det, second);
08775
08776 cout << "First point SEIDs: " << pt1.size() << endl;
08777 cout << "Second point SEIDs: " << pt2.size() << endl;
08778
08779
08780 TH1D gaindiff("gaindiff", "Difference in gains", 120, -30, 30);
08781
08782
08783
08784 for (map<Int_t,Double_t>::const_iterator it = pt1.begin(); it != pt1.end(); ++it) {
08785 UInt_t seid = it->first;
08786 Double_t gain = it->second;
08787
08788
08789 if (!pt2.count(seid)) {
08790 MSG("LIPlexMaps",Msg::kFatal) << "Second timestamp does not have stripend-id " << seid << endl;
08791 throw runtime_error("Timestamps do not have matching SEIDs");
08792 }
08793
08794 Int_t plane=-1;
08795 Int_t strip=-1;
08796 Int_t end=-1;
08797 fLookup.UnencodePlnStripEndKey(seid,det,plane,strip,end);
08798
08799
08800 Double_t diff = pt2[seid] - gain;
08801
08802
08803 gaindiff.Fill(diff);
08804
08805
08806 }
08807
08808
08809
08810
08811
08812
08813
08814 return gaindiff;
08815
08816 }
08817
08818 TH2D LIPlexMaps::GainDifferenceSvP(Detector::Detector_t det, VldTimeStamp first, VldTimeStamp second)
08819 {
08820 LIPlexMaps LIPlex;
08821
08822
08823 std::map<Int_t,Double_t> pt1 = LIPlex.GetGainMap(det, first);
08824 std::map<Int_t,Double_t> pt2 = LIPlex.GetGainMap(det, second);
08825
08826 cout << "First point SEIDs: " << pt1.size() << endl;
08827 cout << "Second point SEIDs: " << pt2.size() << endl;
08828
08829 Int_t maxp, maxs;
08830 if (det == Detector::kFar) {
08831 maxp = 500;
08832 maxs = 200;
08833 } else {
08834 maxp = 300;
08835 maxs = 100;
08836 }
08837 TH2D stripvsplane("stripvsplane", "Strip versus plane differences", maxp, 0, maxp, maxs, 0, maxs);
08838
08839
08840 for (map<Int_t,Double_t>::const_iterator it = pt1.begin(); it != pt1.end(); ++it) {
08841 UInt_t seid = it->first;
08842 Double_t gain = it->second;
08843
08844
08845 if (!pt2.count(seid)) {
08846 MSG("LIPlexMaps",Msg::kFatal) << "Second timestamp does not have stripend-id " << seid << endl;
08847 throw runtime_error("Timestamps do not have matching SEIDs");
08848 }
08849
08850 Int_t plane=-1;
08851 Int_t strip=-1;
08852 Int_t end=-1;
08853 fLookup.UnencodePlnStripEndKey(seid,det,plane,strip,end);
08854
08855
08856 Double_t diff = pt2[seid] - gain;
08857
08858
08859
08860 stripvsplane.Fill(plane,strip, diff);
08861 }
08862
08863 return stripvsplane;
08864 }
08865
08866 void LIPlexMaps::DumpGains(Detector::Detector_t det, VldTimeStamp ts, std::string gaindump_filename)
08867 {
08868
08869 VldContext vldCtx(det, SimFlag::kData, ts);
08870
08871
08872 DbiResultPtr<CalADCtoPEs> dbiCalADCtoPEs;
08873
08874
08875 Int_t task = 0;
08876 if (det == Detector::kNear) task = 1;
08877
08878
08879
08880 UInt_t numRows = dbiCalADCtoPEs.NewQuery(vldCtx,task);
08881
08882
08883 ofstream gaindump(gaindump_filename.c_str());
08884 if (gaindump.is_open()) {
08885 MSG("LIPlexMaps",Msg::kInfo) << "Dumping gain values to " << gaindump_filename << endl;
08886
08887 gaindump << "#"
08888 << setw(3) << "Pl" << " "
08889 << setw(3) << "Str" << " "
08890 << setw(3) << "End" << " "
08891 << setw(4) << "Agg" << " "
08892 << setw(6) << "SEID" << " "
08893 << setw(9) << "Gain" << " "
08894 << setw(9) << "Error"
08895 << "\n";
08896
08897 } else {
08898 MSG("LIPlexMaps",Msg::kFatal) << "Error writing to gain dump file " << gaindump_filename << endl;
08899 }
08900
08901
08902 for (UInt_t i = 0; i < numRows; ++i)
08903 {
08904
08905 const CalADCtoPEs* calAdcToPe = dbiCalADCtoPEs.GetRow(i);
08906
08907
08908 Int_t aggno = calAdcToPe->GetAggregateNo();
08909 Float_t gain = calAdcToPe->GetGain();
08910 Float_t gainerr = calAdcToPe->GetGainErr();
08911 Int_t seid = calAdcToPe->GetSEIDkey();
08912
08913
08914 Int_t plane=-1;
08915 Int_t strip=-1;
08916 Int_t end=-1;
08917 fLookup.UnencodePlnStripEndKey(seid,det,plane,strip,end);
08918
08919
08920 gaindump << setw(4) << plane << " "
08921 << setw(3) << strip << " "
08922 << setw(3) << end << " "
08923 << setw(4) << aggno << " "
08924 << setw(6) << seid << " "
08925 << setw(9) << gain << " "
08926 << setw(9) << gainerr
08927 << "\n";
08928 }
08929 }