00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021 #include "TAxis.h"
00022 #include "TCanvas.h"
00023 #include "TGraph.h"
00024 #include "TH1.h"
00025 #include "TH2.h"
00026 #include "TLine.h"
00027 #include "TObjArray.h"
00028 #include "TString.h"
00029 #include "TStyle.h"
00030
00031 #include "CandData/CandRecord.h"
00032 #include "Conventions/Munits.h"
00033 #include "JobControl/JobCModuleRegistry.h"
00034 #include "JobControl/JobCommand.h"
00035 #include "MessageService/MsgService.h"
00036 #include "MinosObjectMap/MomNavigator.h"
00037 #include "UgliGeometry/UgliGeomHandle.h"
00038 #include "BubbleSpeak/CandDigiPairHandle.h"
00039 #include "BubbleSpeak/CandDigiPairListHandle.h"
00040 #include "BubbleSpeak/CandMSTClusterListHandle.h"
00041 #include "BubbleSpeak/CandStraightClusterHandle.h"
00042 #include "BubbleSpeak/CandThruMuonHandle.h"
00043 #include "BubbleSpeak/CandThruMuonListHandle.h"
00044 #include "BubbleSpeak/PlotMuonClusterModule.h"
00045
00046 #include <iostream.h>
00047 #include <fstream.h>
00048
00049
00050
00051 CVSID("$Id: PlotMuonClusterModule.cxx,v 1.1 2002/06/24 16:27:36 bv Exp $");
00052
00053
00054
00055
00056
00057 JOBMODULE(PlotMuonClusterModule,
00058 "PlotMuonClusterModule",
00059 "Plots the clusters of muons from a CandThruMuonList");
00060
00061
00062
00063 PlotMuonClusterModule::PlotMuonClusterModule() :
00064 fListClust(""), fListMuon(""),
00065 fAnaCanvas(0)
00066 {
00067
00068
00069
00070
00071
00072
00073
00074
00075 MSG("BubJobC", Msg::kDebug)
00076 << "PlotMuonClusterModule::Constructor" << endl;
00077 for (int i=0; i<4; i++) {
00078 fAnaBlanks[i] = 0;
00079 fAnaGraphs[i] = 0;
00080 }
00081 for (int i=0; i<2; i++) {
00082 fAnaFits[i] = 0;
00083 }
00084 }
00085
00086
00087
00088 PlotMuonClusterModule::~PlotMuonClusterModule()
00089 {
00090
00091
00092
00093
00094
00095
00096
00097
00098 MSG("BubJobC", Msg::kDebug)
00099 << "PlotMuonClusterModule::Destructor" << endl;
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 }
00129
00130
00131
00132 JobCResult PlotMuonClusterModule::Ana(const MomNavigator *mom)
00133 {
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 MSG("BubJobC", Msg::kDebug) << "PlotMuonClusterModule::Ana" << endl;
00146
00147
00148 CandRecord *candrec = dynamic_cast<CandRecord *>
00149 (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00150 if (candrec == 0) {
00151 MSG("BubJobC", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00152 << endl;
00153 return JobCResult::kError;
00154 }
00155
00156 CandMSTClusterListHandle *cllh=dynamic_cast<CandMSTClusterListHandle*>
00157 (candrec->FindCandHandle("CandMSTClusterListHandle",
00158 fListClust.Data()));
00159 CandThruMuonListHandle *cmlh = dynamic_cast<CandThruMuonListHandle *>
00160 (candrec->FindCandHandle("CandThruMuonListHandle",
00161 fListMuon.Data()));
00162
00163 MSG("BubJobC", Msg::kDebug) << "before plot" << endl;
00164 PlotClusters(*cllh, *cmlh);
00165 MSG("BubJobC", Msg::kDebug) << "after plot" << endl;
00166
00167 return JobCResult::kAOK;
00168 }
00169
00170
00171
00172 void PlotMuonClusterModule::HandleCommand(JobCommand *command)
00173 {
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 MSG("BubJobC", Msg::kDebug)
00196 << "PlotMuonClusterModule::HandleCommand" <<endl;
00197
00198 TString cmd = command->PopCmd();
00199
00200
00201 if (cmd == "Set") {
00202 TString opt = command->PopOpt();
00203 if (opt == "ListClust") fListClust = command->PopOpt();
00204 else if (opt == "ListMuon") fListMuon = command->PopOpt();
00205 else {
00206 MSG("BubJobC", Msg::kWarning)
00207 << "PlotMuonClusterModule: Unrecognized option " << opt
00208 << endl;
00209 }
00210 }
00211
00212
00213 else if (cmd == "Plot") RedrawPlot();
00214
00215
00216 else if (cmd == "SetPlot") {
00217 TString opt = command->PopOpt();
00218 if (opt == "Zmin")
00219 fAnaZmin = command->PopFloatOpt() * Munits::cm;
00220 else if (opt == "Zmax")
00221 fAnaZmax = command->PopFloatOpt() * Munits::cm;
00222 else if (opt == "Umin")
00223 fAnaTmin[0] = command->PopFloatOpt() * Munits::cm;
00224 else if (opt == "Umax")
00225 fAnaTmax[0] = command->PopFloatOpt() * Munits::cm;
00226 else if (opt == "Vmin")
00227 fAnaTmin[1] = command->PopFloatOpt() * Munits::cm;
00228 else if (opt == "Vmax")
00229 fAnaTmax[1] = command->PopFloatOpt() * Munits::cm;
00230 else {
00231 MSG("BubJobC", Msg::kWarning)
00232 << "PlotMuonClusterModule: Unrecognized option " << opt
00233 << endl;
00234 }
00235 }
00236
00237
00238 else {
00239 MSG("BubJobC", Msg::kWarning)
00240 << "PlotMuonClusterModule: Unrecognized command " << cmd << endl;
00241 }
00242 }
00243
00244
00245
00246 void PlotMuonClusterModule::Help()
00247 {
00248
00249
00250
00251
00252
00253
00254
00255
00256 MSG("BubJobC", Msg::kInfo)
00257 << "Help for 'PlotMuonClusterModule':" << endl
00258 << " PlotMuonClusterModule is a module for viewing clusters" << endl
00259 << " and fitted muon tracks to allow a visual comparison of" << endl
00260 << " the results of fit rejection. The clusters are" << endl
00261 << " displayed by adding:" << endl
00262 << " PlotMuonClusterModule::Ana" << endl
00263 << " to the Path to be run. Note that the colours between" << endl
00264 << " the two cluster graphs do not necessarily correspond," << endl
00265 << " but do for the muon tracks." << endl
00266 << endl
00267 << "Commands implemented:" << endl
00268 << " /PlotMuonClusterModule/Set ListClust <listname>" << endl
00269 << " Set name of CandMSTClusterList to retrieve." << endl
00270 << " /PlotMuonClusterModule/Set ListMuon <listname>" << endl
00271 << " Set name of CandThruMuonList to retrieve." << endl
00272 << endl
00273 << " /PlotMuonClusterModule/Plot" << endl
00274 << " Draw cluster plot with current limits." << endl
00275 << " /PlotMuonClusterModule/SetPlot <Zmin/Zmax/Umin/Umax/Vmin/Vmax>"
00276 << " <value>" << endl
00277 << " Set axis limit value. The command" << endl
00278 << " /PlotMuonClusterModule/Plot" << endl
00279 << " must be reissued afterwards to update the plot." << endl
00280 << endl;
00281 }
00282
00283
00284
00285 void PlotMuonClusterModule::PlotClusters(
00286 const CandMSTClusterListHandle &cllh,
00287 const CandThruMuonListHandle &cmlh)
00288 {
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 iEvent++;
00303
00304
00305 for (Int_t i=0; i<4; i++) {
00306 if (fAnaGraphs[i]) {
00307 fAnaGraphs[i]->Delete();
00308 delete fAnaGraphs[i];
00309 }
00310 fAnaGraphs[i] = new TObjArray();
00311 }
00312 for (Int_t i=0; i<2; i++) {
00313 if (fAnaFits[i]) {
00314 fAnaFits[i]->Delete();
00315 delete fAnaFits[i];
00316 }
00317 fAnaFits[i] = new TObjArray();
00318 }
00319
00320
00321 UgliGeomHandle ugh(*cllh.GetVldContext());
00322 ugh.GetTransverseExtent(PlaneView::kU, fAnaTmin[0], fAnaTmax[0]);
00323 ugh.GetTransverseExtent(PlaneView::kV, fAnaTmin[1], fAnaTmax[1]);
00324 ugh.GetZExtent(fAnaZmin, fAnaZmax);
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 Int_t npts[2] = { 0,0 };
00338 CandMSTClusterHandleItr clhItr(cllh.GetDaughterIterator());
00339 while (CandMSTClusterHandle *clh = clhItr()) {
00340
00341 MSG("BubJobC", Msg::kDebug) << "before strip orientation" << endl;
00342
00343
00344 Int_t clusv = -1;
00345 switch (clh->GetPlaneView()) {
00346 case PlaneView::kU:
00347 clusv = 0;
00348 break;
00349 case PlaneView::kV:
00350 clusv = 1;
00351 break;
00352 case PlaneView::kA:
00353 case PlaneView::kB:
00354 MSG("BubJobC", Msg::kInfo)
00355 << "Plane views A and B not plotted." << endl;
00356 continue;
00357 break;
00358 default:
00359 MSG("BubJobC", Msg::kWarning)
00360 << "Unrecognized strip orientation." << endl;
00361 continue;
00362 }
00363
00364 MSG("BubJobC", Msg::kDebug) << "after strip orientation" << endl;
00365
00366
00367 MSG("BubJobC", Msg::kDebug) << "start TGraph" << endl;
00368 TGraph *clusg = new TGraph();
00369 Int_t cluspts = 0;
00370 CandDigiPairHandleItr chhItr(clh->GetDaughterIterator());
00371 MSG("BubJobC", Msg::kDebug) << "after GetDaughterIterator" << endl;
00372
00373
00374
00375
00376
00377
00378 MSG("BubJobC", Msg::kDebug) << "after Iteration" << endl;
00379 clusg->SetMarkerStyle(8);
00380 clusg->SetMarkerSize(0.5);
00381 clusg->SetMarkerColor(npts[clusv]+2);
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 fAnaGraphs[2*clusv]->AddAtAndExpand(clusg, npts[clusv]++);
00395 }
00396
00397
00398
00399 MSG("BubJobC", Msg::kDebug) << "Iterate over muons." << endl;
00400 Int_t nmus = 0;
00401 CandThruMuonHandleItr cmhItr(cmlh.GetDaughterIterator());
00402 while (CandThruMuonHandle *cmh = cmhItr()) {
00403
00404
00405 const CandStraightClusterHandle *cchU = cmh->GetClusterU();
00406 TGraph *clusg = new TGraph();
00407 Int_t cluspts = 0;
00408 Int_t clusU=0;
00409 Float_t chiSqU=0;
00410 Float_t trueTransU=0;
00411 CandDigiPairHandleItr chhUItr(cchU->GetDaughterIterator());
00412 while (CandDigiPairHandle *chhU = chhUItr()) {
00413 clusg->SetPoint(cluspts++, chhU->GetZPos(), chhU->GetTPos());
00414
00415 clusU++;
00416 chiSqU += (chhU->GetTPos() - cmh->GetFitUFromZ(chhU->GetZPos()))*
00417 (chhU->GetTPos() - cmh->GetFitUFromZ(chhU->GetZPos()));
00418
00419 }
00420
00421 chiSqU /= 0.0001*clusU;
00422 cout << "clusU, chiSqU: " << clusU << " " << chiSqU << endl;
00423 clusU=0;
00424 if(chiSqU < fMaxChiSq){
00425 CandDigiPairHandleItr chhUItr2(cchU->GetDaughterIterator());
00426 while (CandDigiPairHandle *chhU = chhUItr2()) {
00427 clusg->SetPoint(cluspts++, chhU->GetZPos(), chhU->GetTPos());
00428 clusU++;
00429 ofstream out("./tracks_data.out", ios::app);
00430 out << iEvent << " " << 0 << " " << clusU << " "
00431 << chhU->GetZPos() << " " << chhU->GetTPos() << " "
00432 << chhU->GetPlane() << " " << chhU->GetCharge() << endl;
00433 }
00434 }
00435
00436 clusg->SetMarkerStyle(8);
00437 clusg->SetMarkerSize(0.5);
00438 clusg->SetMarkerColor(nmus+2);
00439 fAnaGraphs[1]->AddAtAndExpand(clusg, nmus);
00440
00441
00442 const CandStraightClusterHandle *cchV = cmh->GetClusterV();
00443 clusg = new TGraph();
00444 cluspts = 0;
00445 Int_t clusV=0;
00446 Float_t chiSqV=0;
00447 Float_t trueTransV=0;
00448 CandDigiPairHandleItr chhVItr(cchV->GetDaughterIterator());
00449 while (CandDigiPairHandle *chhV = chhVItr()) {
00450 clusg->SetPoint(cluspts++, chhV->GetZPos(), chhV->GetTPos());
00451
00452 clusV++;
00453 chiSqV += (chhV->GetTPos() - cmh->GetFitVFromZ(chhV->GetZPos()))*
00454 (chhV->GetTPos() - cmh->GetFitVFromZ(chhV->GetZPos()));
00455
00456
00457 }
00458 chiSqV /= 0.0001*clusV;
00459 cout << "clusV, chiSqV: " << clusV << " " << chiSqV << endl;
00460 clusV=0;
00461 if(chiSqV < fMaxChiSq){
00462 CandDigiPairHandleItr chhVItr2(cchV->GetDaughterIterator());
00463 while (CandDigiPairHandle *chhV = chhVItr2()) {
00464 clusg->SetPoint(cluspts++, chhV->GetZPos(), chhV->GetTPos());
00465 clusV++;
00466 ofstream out("./tracks_data.out", ios::app);
00467 out << iEvent << " " << 1 << " " << clusV << " "
00468 << chhV->GetZPos() << " " << chhV->GetTPos() << " "
00469 << chhV->GetPlane() << " " << chhV->GetCharge()<< endl;
00470 }
00471 }
00472
00473 clusg->SetMarkerStyle(8);
00474 clusg->SetMarkerSize(0.5);
00475 clusg->SetMarkerColor(nmus+2);
00476 fAnaGraphs[3]->AddAtAndExpand(clusg, nmus);
00477
00478
00479 Float_t zbeg = cmh->GetZBeg();
00480 Float_t zend = cmh->GetZEnd();
00481 Float_t ubeg = cmh->GetFitUFromZ(zbeg);
00482 Float_t uend = cmh->GetFitUFromZ(zend);
00483 Float_t vbeg = cmh->GetFitVFromZ(zbeg);
00484 Float_t vend = cmh->GetFitVFromZ(zend);
00485
00486
00487 TLine *fitl = new TLine(zbeg, ubeg, zend, uend);
00488 fitl->SetLineColor(nmus+2);
00489 fAnaFits[0]->AddAtAndExpand(fitl, nmus);
00490 fitl = new TLine(zbeg, vbeg, zend, vend);
00491 fitl->SetLineColor(nmus+2);
00492 fAnaFits[1]->AddAtAndExpand(fitl, nmus++);
00493
00494
00495 if (zbeg < fAnaZmin) fAnaZmin = zbeg;
00496 if (zend > fAnaZmax) fAnaZmax = zend;
00497 if (ubeg < fAnaTmin[0]) fAnaTmin[0] = ubeg;
00498 if (ubeg > fAnaTmax[0]) fAnaTmax[0] = ubeg;
00499 if (uend < fAnaTmin[0]) fAnaTmin[0] = uend;
00500 if (uend > fAnaTmax[0]) fAnaTmax[0] = uend;
00501 if (vbeg < fAnaTmin[1]) fAnaTmin[1] = vbeg;
00502 if (vbeg > fAnaTmax[1]) fAnaTmax[1] = vbeg;
00503 if (vend < fAnaTmin[1]) fAnaTmin[1] = vend;
00504 if (vend > fAnaTmax[1]) fAnaTmax[1] = vend;
00505 }
00506
00507
00508 MSG("BubJobC", Msg::kDebug) << "Draw plot" << endl;
00509 RedrawPlot();
00510 }
00511
00512
00513
00514 void PlotMuonClusterModule::RedrawPlot()
00515 {
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 gStyle->SetOptStat(0);
00526
00527
00528 if (fAnaCanvas) fAnaCanvas->Clear("D");
00529 else {
00530 fAnaCanvas = new TCanvas("PlotMuonCanvas", "Muon Cluster Canvas",
00531 1200, 700);
00532 fAnaCanvas->SetFillColor(0);
00533 fAnaCanvas->Divide(2, 2);
00534 }
00535
00536
00537 for (Int_t i=0; i<4; i++) {
00538 fAnaCanvas->cd(i+1);
00539 gPad->SetGrid();
00540
00541
00542 delete fAnaBlanks[i];
00543 char blankname[80];
00544 sprintf(blankname, "blank%d", i+1);
00545 fAnaBlanks[i] = new TH2F(blankname, "Clusters",
00546 2, fAnaZmin, fAnaZmax, 2, fAnaTmin[i/2], fAnaTmax[i/2]);
00547
00548 TString xtitle("z-value (");
00549 xtitle += Munits::base_length_name;
00550 xtitle += ")";
00551
00552 fAnaBlanks[i]->SetXTitle(const_cast<char*>(xtitle.Data()));
00553
00554 TString ytitle((i/2 ? "v-value (" : "u-value ("));
00555 ytitle += Munits::base_length_name;
00556 ytitle += ")";
00557
00558 fAnaBlanks[i]->SetYTitle(const_cast<char*>(ytitle.Data()));
00559
00560 fAnaBlanks[i]->Draw();
00561
00562
00563 for (Int_t j=0; j<fAnaGraphs[i]->GetEntries(); j++) {
00564 if (TGraph *grj = (TGraph*) fAnaGraphs[i]->At(j)) grj->Draw("P");
00565 }
00566 }
00567
00568
00569 for (Int_t i=0; i<2; i++) {
00570 fAnaCanvas->cd(2*i+2);
00571 for (Int_t j=0; j<fAnaFits[i]->GetEntries(); j++) {
00572 if (TLine *fitl = dynamic_cast<TLine *>(fAnaFits[i]->At(j)))
00573 fitl->Draw();
00574 }
00575 }
00576
00577
00578 fAnaCanvas->Update();
00579 }