00001
00002
00003
00004
00005
00006
00008 #include "ChopModule.h"
00009 #include "MessageService/MsgService.h"
00010 #include "MinosObjectMap/MomNavigator.h"
00011 #include "JobControl/JobCModuleRegistry.h"
00012 #include "Algorithm/AlgFactory.h"
00013 #include "CandData/CandRecord.h"
00014 #include "Candidate/CandContext.h"
00015 #include "CandDigit/CandDigitListHandle.h"
00016 #include "RecoBase/CandSliceListHandle.h"
00017 #include "RecoBase/CandSliceHandle.h"
00018 #include "CandChopListHandle.h"
00019 #include "CandChopList.h"
00020 #include "DigitVector.h"
00021
00022 #include "DataUtil/Truthifier.h"
00023 #include "DataUtil/GetRunSnarlEvent.h"
00024 #include "UgliGeometry/UgliGeomHandle.h"
00025
00026 #include "Calibrator/Calibrator.h"
00027
00028
00029 #include <TFile.h>
00030 #include <TTree.h>
00031 #include <TCanvas.h>
00032 #include <TH1.h>
00033 #include <TH2.h>
00034 #include <TGraph.h>
00035 #include <TStyle.h>
00036
00037 JOBMODULE(ChopModule, "ChopModule",
00038 "Chops digits into Chops (digitslices)");
00039 CVSID("$Id: ChopModule.cxx,v 1.7 2007/11/11 08:26:13 rhatcher Exp $");
00040
00041
00042
00043
00044
00045 ChopModule::ChopModule() :
00046 fFile(0),
00047 fTree(0),
00048 fNuTree(0),
00049 fCanvas1(0),
00050 fCanvas2(0),
00051 fCanvas3(0),
00052 fleaf(0),
00053 fnu(0)
00054 {
00059 }
00060
00061
00062
00063 ChopModule::~ChopModule()
00064 {
00065
00066 if(fFile) {
00067 fTree->Write();
00068 fNuTree->Write();
00069 fFile->Write();
00070 fFile->Close();
00071 }
00072
00073 }
00074
00075
00076
00077 JobCResult ChopModule::Reco(MomNavigator* mom)
00078 {
00079 JobCResult result = JobCResult::kPassed;
00080
00081
00082 Registry& cfg = this->GetConfig();
00083 const char* algName = cfg.GetCharString("ChopAlgorithm");
00084 const char* algConfigName = cfg.GetCharString("ChopAlgConfig");
00085 const char* listIn = cfg.GetCharString("ListIn");
00086 const char* listOut = cfg.GetCharString("ListOut");
00087
00088
00089
00090 CandRecord *candrec = dynamic_cast<CandRecord *>
00091 (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00092 if (candrec == 0) {
00093 MSG("Chop", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00094 << endl;
00095 result.SetWarning().SetFailed();
00096 return result;
00097 }
00098
00099 CandDigitListHandle *cdlh = dynamic_cast<CandDigitListHandle *>
00100 (candrec->FindCandHandle("CandDigitListHandle", listIn));
00101
00102
00103 if (!cdlh || cdlh->GetNDaughters() < 1) {
00104 MSG("StripSR", Msg::kDebug)
00105 << "Null CandDigit list. Bail out of event." << endl;
00106 result.SetFailed();
00107 return result;
00108 }
00109
00110 AlgFactory &af = AlgFactory::GetInstance();
00111 AlgHandle adlh = af.GetAlgHandle(algName,algConfigName);
00112 CandContext cx(this, mom);
00113 cx.SetCandRecord(candrec);
00114 cx.SetDataIn(cdlh);
00115
00116 CandChopListHandle chopListH = CandChopList::MakeCandidate(adlh, cx);
00117 chopListH.SetName(listOut);
00118 chopListH.SetTitle(Form("Chop list created by alg %s config %s",
00119 algName, algConfigName) );
00120 candrec->SecureCandHandle(chopListH);
00121
00122
00123 return JobCResult::kPassed;
00124 }
00125
00126
00127
00129 const RawChannelId kQieRcid(Detector::kNear,ElecType::kQIE,0,0,false,false);
00130
00131 class Hi
00132 { public:
00133 int index;
00134 float time;
00135 Hi(int i, float t) : index(i), time(t) {};
00136 bool operator<(const class Hi& other) const { return time < other.time; };
00137 };
00138
00139 void TimeRankHistos(UInt_t n, std::vector<TH1*> inHists, std::vector<int>& outRank)
00140 {
00141 outRank.resize(n);
00142
00143 std::vector<Hi> sorter;
00144 for(UInt_t i=0;i<n;i++) {
00145 sorter.push_back(Hi(i,inHists[i]->GetMean()));
00146 }
00147 std::sort(sorter.begin(),sorter.end());
00148
00149 for(UInt_t i=0;i<n;i++) {
00150 outRank[sorter[i].index] = i;
00151 }
00152 }
00153
00154
00155 JobCResult ChopModule::Ana(const MomNavigator* mom)
00156 {
00157 JobCResult result;
00158
00159
00160 CandRecord *candrec = dynamic_cast<CandRecord *>
00161 (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00162 if (candrec == 0) {
00163 MSG("Chop", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00164 << endl;
00165 result.SetWarning().SetFailed();
00166 return result;
00167 }
00168
00169 CandDigitListHandle *cdlh_ptr = dynamic_cast<CandDigitListHandle *>
00170 (candrec->FindCandHandle("CandDigitListHandle", "canddigitlist"));
00171 if(cdlh_ptr==0) {
00172 MSG("Chop", Msg::kWarning) << "Couldn't find CandDigitListHandle." << endl;
00173 return JobCResult::kError;
00174 }
00175
00176
00177 VldContext context = *(cdlh_ptr->GetVldContext());
00178 if(context.GetSimFlag() != SimFlag::kMC) {
00179
00180
00181 }
00182
00183
00184 CandChopListHandle *choplist_ptr = dynamic_cast<CandChopListHandle *>
00185 (candrec->FindCandHandle("CandChopListHandle", "candchoplist"));
00186 if(choplist_ptr==0) {
00187 MSG("Chop", Msg::kWarning) << "Can't find ChopListHandle." << endl;
00188 }
00189
00190 CandSliceListHandle *srslicelist_ptr = dynamic_cast<CandSliceListHandle *>
00191 (candrec->FindCandHandle("CandSliceListHandle", "CandSliceList"));
00192
00193
00194
00195 bool haveTruth = false;
00196 SimSnarlRecord *ssr =
00197 dynamic_cast<SimSnarlRecord*>(mom->GetFragment("SimSnarlRecord"));
00198 if (!ssr){
00199 MSG("Chop", Msg::kWarning) << "ChopModule::Ana couldn't find SimSnarl data, which it needs." << endl;
00200 haveTruth = false;
00201 } else {
00202 haveTruth = true;
00203 }
00204
00206
00207 double particleTimeout = GetConfig().GetDouble("particleTimeout");
00208 const char* filename = GetConfig().GetCharString("filename");
00209 int plots = GetConfig().GetInt("plots");
00210
00212
00213 TDirectory* oldDir = gDirectory;
00214
00215 if(fFile==0) {
00216 fFile = new TFile(filename,"RECREATE");
00217 fFile->cd();
00218
00219 fleaf = new ChopTreeLeaf;
00220 fTree = new TTree("mytree","mytree");
00221 fTree->Branch("chopbr","ChopTreeLeaf",&fleaf);
00222 fTree->Write();
00223
00224 fnu = new ChopNeutrinoLeaf;
00225 fNuTree = new TTree("nutree","nutree");
00226 fNuTree->Branch("nubr","ChopNeutrinoLeaf",&fnu);
00227 fNuTree->Write();
00228
00229 fFile->Write();
00230 }
00231 assert(fFile);
00232 fFile->cd();
00233
00234
00236
00237
00238
00239 int run = -1, snarl = -1, event = -1;
00240 DataUtil::GetRunSnarlEvent(mom,run,snarl,event);
00241
00242 const Truthifier& truth = Truthifier::Instance(mom);
00243
00244
00245 UgliGeomHandle ugli(context);
00246
00247
00248
00249
00250
00252
00253
00254 for(UInt_t ih = 0; ih<fCleanup.size(); ih++) delete fCleanup[ih];
00255 fCleanup.clear();
00256
00258
00259 DigitVector allDigits(cdlh_ptr);
00260
00262
00263 std::vector<DigitVector> chopList;
00264 if(choplist_ptr) {
00265 chopList.resize(choplist_ptr->GetNDaughters());
00266
00267 CandDigitListHandleItr chopItr(choplist_ptr->GetDaughterIterator());
00268 UInt_t ichop=0;
00269 while( CandDigitListHandle* cdlh= chopItr() ) {
00270 chopList[ichop++].FillFrom(cdlh);
00271 }
00272 MSG("Chop",Msg::kDebug) << "Found " << chopList.size() << " Chops." << endl;
00273 }
00275
00276 std::vector<DigitVector> refSliceList;
00277
00278 if(srslicelist_ptr) {
00279 refSliceList.resize(srslicelist_ptr->GetNDaughters());
00280 CandSliceHandleItr cshItr(srslicelist_ptr->GetDaughterIterator());
00281
00282 UInt_t ichop=0;
00283 while(CandSliceHandle* slice = cshItr()) {
00284 refSliceList[ichop++].FillFrom(slice);
00285 }
00286 }
00287 MSG("Chop",Msg::kDebug) << "Found " << refSliceList.size() << " SR Slices." << endl;
00288
00290
00291
00292 int tfirst = 90000000;
00293 int tlast = -1;
00294 for(UInt_t idig = 0; idig<allDigits.size(); idig++) {
00295 CandDigitHandle cdh = allDigits[idig];
00296 int tdc = Calibrator::Instance().GetTDCFromTime(cdh.GetTime(CalTimeType::kNone), kQieRcid);
00297
00298
00299 if(tdc<tfirst) tfirst = tdc;
00300 if(tdc>tlast) tlast = tdc;
00301 }
00302
00303 tfirst -= 5;
00304 tlast += 5;
00305
00306
00307 std::vector<Int_t> neutrinos(0);
00308 std::vector<TH1*> nuHist(neutrinos.size());
00309 std::vector<TH1*> nuHistInt(neutrinos.size());
00310 std::vector<float> nuGraphTdc;
00311 std::vector<float> nuGraphPlane;
00312 std::vector<float> nuGraphE;
00313 std::vector<int> nuGraphNu;
00314 std::vector<UInt_t> nuNGraph(neutrinos.size(),0);
00315
00316 if(haveTruth) {
00317
00319
00320 neutrinos = truth.GetListOfNeutrinoIndecies();
00321
00323
00324
00325 vector<double> nuTZero(neutrinos.size(),1e19);
00326
00327
00328 for(Int_t s=0;s<truth.GetScintHitListSize(); s++) {
00329 const DigiScintHit* hit = truth.GetScintHit(s);
00330 if(hit){
00331 int nu_index = truth.GetNeutrinoOfTrack(hit->TrackId());
00332 for(UInt_t inu=0;inu<neutrinos.size();inu++) {
00333 if(neutrinos[inu]==nu_index){
00334 double t = hit->T1();
00335 if(t<nuTZero[inu]) nuTZero[inu]=t;
00336 }
00337 }
00338 }
00339 }
00340
00343
00344 ChopEvaluation allEval;
00345 allEval.Evaluate(allDigits,
00346 truth, neutrinos,nuTZero, particleTimeout);
00347
00349
00350 std::vector< std::vector<CandDigitHandle> >nuDigits(neutrinos.size());
00351 std::vector<ChopEvaluation> nuEval(neutrinos.size());
00352
00353 for(UInt_t idig=0;idig<allDigits.size(); idig++) {
00354 for(UInt_t inu=0; inu < neutrinos.size(); inu++) {
00355
00356 float fract = truth.IsDigitFromNeutrino(neutrinos[inu],allDigits[idig],nuTZero[inu]+particleTimeout);
00357 if(fract>0) nuDigits[inu].push_back(allDigits[idig]);
00358 }
00359 }
00360
00361 for(UInt_t inu=0; inu < neutrinos.size(); inu++) {
00362 nuEval[inu].Evaluate(nuDigits[inu],
00363 truth, neutrinos,nuTZero, particleTimeout);
00364 }
00365
00367
00368 std::vector<ChopNeutrinoInfo> nuInfo(neutrinos.size());
00369
00370 for(UInt_t inu=0; inu < neutrinos.size(); inu++) {
00371 const REROOT_NeuKin* neukin = truth.GetNeuKin(inu);
00372 const TParticle* part = truth.GetStdHepParticle(neutrinos[inu]);
00373 if(!neukin) continue;
00374 if(!part) continue;
00375 nuInfo[inu].inu = inu;
00376 nuInfo[inu].vtxt = part->T();
00377 nuInfo[inu].vtxtdc = Calibrator::Instance().GetTDCFromTime(part->T(),kQieRcid);
00378 nuInfo[inu].vtxx = part->Vx();
00379 nuInfo[inu].vtxy = part->Vy();
00380 nuInfo[inu].vtxz = part->Vz();
00381 nuInfo[inu].enu = neukin-> P4Neu()[3];
00382 nuInfo[inu].emu = neukin-> P4Mu1()[3] + neukin->P4Mu2()[3];
00383 nuInfo[inu].eem = neukin-> P4El1()[3] + neukin->P4El2()[3];
00384 nuInfo[inu].eshw = neukin-> P4Shw()[3];
00385 nuInfo[inu].evis = nuInfo[inu].emu+nuInfo[inu].eem+nuInfo[inu].eshw;
00386 nuInfo[inu].iaction= neukin-> IAction();
00387 nuInfo[inu].X = neukin->X();
00388 nuInfo[inu].Y = neukin->Y();
00389 nuInfo[inu].tzero = nuTZero[inu];
00390 }
00391
00393
00394 std::vector<ChopEvaluation> chopEval;
00395
00396 if(GetConfig().GetInt("eval_sr") ==0) {
00397
00398 chopEval.resize(chopList.size());
00399 for(UInt_t ichop=0; ichop<chopEval.size(); ichop++) {
00400 chopEval[ichop].Evaluate(chopList[ichop],
00401 truth, neutrinos,nuTZero, particleTimeout);
00402 }
00403 } else {
00404
00405 chopEval.resize(refSliceList.size());
00406 for(UInt_t ichop=0; ichop<chopEval.size(); ichop++) {
00407 chopEval[ichop].Evaluate(refSliceList[ichop],
00408 truth, neutrinos,nuTZero, particleTimeout);
00409 }
00410 }
00411
00413
00415
00416
00417 for(UInt_t ichop = 0; ichop < chopEval.size(); ichop++) {
00418 fleaf->Reset();
00419 fleaf->snarl = snarl;
00420 fleaf->chop = ichop;
00421 (*(ChopEvaluation*)fleaf) = (chopEval[ichop]);
00422
00423
00424
00425 fleaf->complete1 = 0;
00426 fleaf->viscal1 = 0;
00427 fleaf->viscalt1 = 0;
00428 fleaf->visfidt1 = 0;
00429 fleaf->strips1 = 0;
00430 if(chopEval[ichop].fBestNeutrino1>=0) {
00431 (*(ChopNeutrinoInfo*)fleaf) = nuInfo[chopEval[ichop].fBestNeutrino1];
00432 fleaf->complete1 = chopEval[ichop].fNuMatch_calt[chopEval[ichop].fBestNeutrino1] /
00433 allEval.fNuMatch_calt[chopEval[ichop].fBestNeutrino1];
00434 fleaf->viscal1 = allEval.fNuMatch_cal[chopEval[ichop].fBestNeutrino1];
00435 fleaf->viscalt1 = allEval.fNuMatch_calt[chopEval[ichop].fBestNeutrino1];
00436 fleaf->visfidt1 = allEval.fNuMatch_caltfid[chopEval[ichop].fBestNeutrino1];
00437 fleaf->strips1 = allEval.fNuMatch_strips[chopEval[ichop].fBestNeutrino1];
00438 }
00439
00440
00441 fleaf->complete2 = 0;
00442 fleaf->viscal2 = 0;
00443 fleaf->viscalt2 = 0;
00444 fleaf->visfidt2 = 0;
00445 fleaf->strips2 = 0;
00446 if(chopEval[ichop].fBestNeutrino2>=0) {
00447 (*(ChopNeutrinoInfo*)fleaf) = nuInfo[chopEval[ichop].fBestNeutrino2];
00448 fleaf->complete2 = chopEval[ichop].fNuMatch_calt[chopEval[ichop].fBestNeutrino2] /
00449 allEval.fNuMatch_calt[chopEval[ichop].fBestNeutrino2];
00450 fleaf->viscal2 = allEval.fNuMatch_cal[chopEval[ichop].fBestNeutrino2];
00451 fleaf->viscalt2 = allEval.fNuMatch_calt[chopEval[ichop].fBestNeutrino2];
00452 fleaf->visfidt2 = allEval.fNuMatch_caltfid[chopEval[ichop].fBestNeutrino2];
00453 fleaf->strips2 = allEval.fNuMatch_strips[chopEval[ichop].fBestNeutrino2];
00454 }
00455
00456 fTree->Fill();
00457 }
00458
00459
00460
00462
00464
00465 for(UInt_t inu=0; inu < neutrinos.size(); inu++) {
00466
00467
00468
00469 int neutrinoToChop1 = -1;
00470 int neutrinoToChop2 = -1;
00471 float neutrinoComplete1 = 0;
00472 float neutrinoComplete2 = 0;
00473
00474 for(UInt_t ichop = 0; ichop<chopEval.size(); ichop++) {
00475 float complete = chopEval[ichop].fNuMatch_cal[inu]/allEval.fNuMatch_cal[inu];
00476
00477 if(complete>neutrinoComplete1) {
00478 neutrinoComplete1 = complete;
00479 neutrinoToChop1 = ichop;
00480 }
00481 }
00482
00483 for(UInt_t ichop = 0; ichop<chopEval.size(); ichop++) {
00484 float complete = chopEval[ichop].fNuMatch_cal[inu]/allEval.fNuMatch_cal[inu];
00485
00486 if((complete>neutrinoComplete2) && ((int)ichop!= neutrinoToChop1)) {
00487 neutrinoComplete2 = complete;
00488 neutrinoToChop2 = ichop;
00489 }
00490 }
00491
00492 if(allEval.fNuMatch_cal[inu] > 0 ) {
00493 MSG("Chop",Msg::kDebug) << "Neutrino " << inu
00494 << "\tVisCal = " << allEval.fNuMatch_cal[inu]
00495 << " \tTDC = " << nuEval[inu].fBigTdc
00496 << " \tTrueStartTime = " << nuTZero[inu]*1e9 << endl;
00497 if(neutrinoToChop1<0) {
00498 MSG("Chop",Msg::kDebug) << "\t\t missed completely." << endl;
00499 }
00500 else if(chopEval[neutrinoToChop1].fBestNeutrino1!=(int)inu) {
00501 MSG("Chop",Msg::kDebug) << "\t\t"
00502 << " got absorbed ( completeness " << neutrinoComplete1 << ")"
00503 << " by chop " << neutrinoToChop1
00504 << " time: " << chopEval[neutrinoToChop1].fBigTdc
00505 << " which came from a neutrino " << chopEval[neutrinoToChop1].fBestNeutrino1
00506 << " viscalt: " << allEval.fNuMatch_calt[chopEval[neutrinoToChop1].fBestNeutrino1]
00507 << endl;
00508
00509 } else {
00510 MSG("Chop",Msg::kDebug) << "\t\t"
00511 << "matches chop " << neutrinoToChop1
00512 << " completeness = " << neutrinoComplete1
00513 << " Strips: nu/chop/match = "
00514 << allEval.fNuMatch_strips[inu] << "/"
00515 << chopEval[neutrinoToChop1].fStrips << "/"
00516 << chopEval[neutrinoToChop1].fNuMatch_strips[inu]
00517 << endl;
00518 }
00519
00520
00521
00522
00523 }
00524
00525
00526 fnu->Reset();
00527 *((ChopNeutrinoInfo*)fnu) = nuInfo[inu];
00528 *((ChopEvaluation*)fnu) = nuEval[inu];
00529
00530 fnu->snarl = snarl;
00531 fnu->viscal = allEval.fNuMatch_cal[inu];
00532 fnu->viscalt= allEval.fNuMatch_calt[inu];
00533 fnu->visfidt= allEval.fNuMatch_caltfid[inu];
00534 fnu->visfid = allEval.fNuMatch_fid[inu];
00535 fnu->sigcorr= nuEval[inu].fSigcor;
00536 fnu->strips = allEval.fNuMatch_strips[inu];
00537 fnu->calstrips = allEval.fNuMatch_calstrips[inu];
00538
00539 fnu->chop1 = neutrinoToChop1;
00540 if(neutrinoToChop1>=0) {
00541 fnu->complete1 = neutrinoComplete1;
00542 fnu->completet1 = chopEval[neutrinoToChop1].fNuMatch_calt[inu]/allEval.fNuMatch_calt[inu];
00543 fnu->complete_tot1 = chopEval[neutrinoToChop1].fNuMatch[inu]/allEval.fNuMatch[inu];
00544 fnu->strips1 = chopEval[neutrinoToChop1].fStrips;
00545 fnu->calstrips1 = chopEval[neutrinoToChop1].fCalStrips;
00546 fnu->stripsmatch1 = chopEval[neutrinoToChop1].fNuMatch_strips[inu];
00547 fnu->calstripsmatch1= chopEval[neutrinoToChop1].fNuMatch_calstrips[inu];
00548 fnu->chop1_sigcorr= chopEval[neutrinoToChop1].fSigcor;
00549 fnu->chop1_viscal = chopEval[neutrinoToChop1].fSigcor_cal;
00550 fnu->chop1_visfid = chopEval[neutrinoToChop1].fSigcor_fid;
00551 fnu->chop1_nu = chopEval[neutrinoToChop1].fBestNeutrino1;
00552 fnu->chop1_tdc = chopEval[neutrinoToChop1].fBigTdc;
00553 fnu->chop1_planebeg= chopEval[neutrinoToChop1].fPlaneBeg;
00554 fnu->chop1_planeend= chopEval[neutrinoToChop1].fPlaneEnd;
00555 }
00556
00557 fnu->chop2 = neutrinoToChop2;
00558 if(neutrinoToChop2>=0) {
00559 fnu->complete2 = neutrinoComplete2;
00560 fnu->completet2 = chopEval[neutrinoToChop2].fNuMatch_calt[inu]/allEval.fNuMatch_calt[inu];
00561 fnu->complete_tot2 = chopEval[neutrinoToChop2].fNuMatch[inu]/allEval.fNuMatch[inu];
00562 fnu->strips2 = chopEval[neutrinoToChop2].fStrips;
00563 fnu->calstrips2 = chopEval[neutrinoToChop2].fCalStrips;
00564 fnu->stripsmatch2 = chopEval[neutrinoToChop2].fNuMatch_strips[inu];
00565 fnu->calstripsmatch2 = chopEval[neutrinoToChop2].fNuMatch_calstrips[inu];
00566 fnu->chop2_sigcorr= chopEval[neutrinoToChop2].fSigcor;
00567 fnu->chop2_viscal = chopEval[neutrinoToChop2].fSigcor_cal;
00568 fnu->chop2_visfid = chopEval[neutrinoToChop2].fSigcor_fid;
00569 fnu->chop2_nu = chopEval[neutrinoToChop2].fBestNeutrino1;
00570 fnu->chop2_tdc = chopEval[neutrinoToChop2].fBigTdc;
00571 fnu->chop2_planebeg= chopEval[neutrinoToChop2].fPlaneBeg;
00572 fnu->chop2_planeend= chopEval[neutrinoToChop2].fPlaneEnd;
00573 }
00574
00575
00576 fNuTree->Fill();
00577 }
00578
00579 if(plots) {
00580 nuHist.resize(neutrinos.size(),0);
00581 nuHistInt.resize(neutrinos.size(),0);
00582 nuNGraph.resize(neutrinos.size(),0);
00583 for(UInt_t inu = 0;inu < neutrinos.size(); inu++) {
00584 nuHist[inu] = new TH1F(Form("nu_%d",inu),
00585 Form("Hits Nu:%d ",inu ),
00586 600, 0, 600);
00587 nuHistInt[inu] = new TH1F(Form("nuint_%d ",inu ),
00588 Form("Hits Nu:%d ",inu),
00589 600, 0, 600);
00590 fCleanup.push_back(nuHist[inu]);
00591 fCleanup.push_back(nuHistInt[inu]);
00592 }
00593
00594
00595
00596
00597
00598 for(UInt_t idig = 0; idig<allDigits.size(); idig++) {
00599 CandDigitHandle cdh = allDigits[idig];
00600 int tdc = Calibrator::Instance().GetTDCFromTime(cdh.GetTime(CalTimeType::kNone), kQieRcid);
00601 float sigcor = cdh.GetCharge(CalDigitType::kSigCorr);
00602 int t = (tdc-tfirst);
00603 int plane = cdh.GetPlexSEIdAltL().GetPlane();
00604 PlexStripEndId seid = cdh.GetPlexSEIdAltL().GetBestSEId();
00605 UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00606
00607 if(plane<121) {
00608
00609 for(UInt_t inu=0;inu<neutrinos.size();inu++) {
00610 int neu = neutrinos[inu];
00611 float frac = truth.IsDigitFromNeutrino(neu,cdh);
00612 float fract = truth.IsDigitFromNeutrino(neu,cdh,nuTZero[inu]+particleTimeout);
00613 if(frac>0) {
00614 nuHist[inu]->Fill(t,fract*sigcor);
00615
00616
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662 nuGraphTdc.push_back(t);
00663 nuGraphPlane.push_back(plane);
00664 nuGraphNu.push_back(inu);
00665 nuGraphE.push_back(frac*sigcor);
00666 nuNGraph[inu]++;
00667 }
00668 }
00669 }
00670 }
00671 }
00672 }
00673
00675
00677
00678
00679 if(plots) {
00680
00681
00682
00683
00684 fFile->cd();
00685 fFile->mkdir(Form("snarl%d",snarl));
00686 fFile->cd(Form("snarl%d",snarl));
00687
00688
00689 TH1* hitHist = 0;
00690 TH2* hit2Hist = 0;
00691 TH2* hitUHist = 0;
00692 TH2* hitVHist = 0;
00693
00694 hitHist = new TH1F(Form("hits"),
00695 Form("Digits Snarl %d",snarl),
00696 600, 0, 600);
00697 fCleanup.push_back(hitHist);
00698
00699 hit2Hist = new TH2F(Form("hits2"),
00700 Form("Hits Vs Plane"),
00701 600,0, 600,
00702 61, 0, 121);
00703 fCleanup.push_back(hit2Hist);
00704
00705 hitUHist = new TH2F(Form("hitsu"),
00706 Form("Hits Vs U TPos"),
00707 600,0, 600,
00708 100, -2, 2);
00709 fCleanup.push_back(hitUHist);
00710
00711 hitVHist = new TH2F(Form("hitsv"),
00712 Form("Hits Vs V TPos"),
00713 600,0, 600,
00714 100, -2, 2);
00715 fCleanup.push_back(hitVHist);
00716
00717 for(UInt_t idig = 0; idig<allDigits.size(); idig++) {
00718 CandDigitHandle cdh = allDigits[idig];
00719 int tdc = Calibrator::Instance().GetTDCFromTime(cdh.GetTime(CalTimeType::kNone), kQieRcid);
00720 float sigcor = cdh.GetCharge(CalDigitType::kSigCorr);
00721 int t = (tdc-tfirst);
00722 int plane = cdh.GetPlexSEIdAltL().GetPlane();
00723 PlaneView::PlaneView_t view = cdh.GetPlexSEIdAltL().GetBestSEId().GetPlaneView();
00724 PlexStripEndId seid = cdh.GetPlexSEIdAltL().GetBestSEId();
00725 UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00726 float tpos = ustrip.GetTPos();
00727
00728 if(plane<121) {
00729 hitHist->Fill (t, sigcor);
00730 hit2Hist->Fill(t, plane, sigcor);
00731
00732 if(view==PlaneView::kU) hitUHist->Fill(t, tpos, sigcor);
00733 else hitVHist->Fill(t, tpos, sigcor);
00734 }
00735 }
00736
00737
00738
00739 std::vector<TH1*> chopHist(chopList.size());
00740 std::vector<TH1*> chopHistInt(chopList.size());
00741 std::vector<float> chopGraphTdc;
00742 std::vector<float> chopGraphPlane;
00743 std::vector<float> chopGraphE;
00744 std::vector<int> chopGraphChop;
00745 std::vector<UInt_t> chopNGraph(chopList.size(),0);
00746
00747 for(UInt_t ichop = 0;ichop < chopList.size(); ichop++) {
00748 chopHist[ichop] = new TH1F(Form("chp_%d",ichop),
00749 Form("Hits Chop:%d",ichop),
00750 600, 0, 600);
00751 chopHistInt[ichop] = new TH1F(Form("chpint_%d",ichop),
00752 Form("Hits Chop:%d ",ichop),
00753 600, 0, 600);
00754 fCleanup.push_back(chopHist[ichop]);
00755 fCleanup.push_back(chopHistInt[ichop]);
00756
00757 for(UInt_t idig = 0; idig < chopList[ichop].size(); idig++) {
00758 CandDigitHandle cdh = chopList[ichop][idig];
00759 int tdc = Calibrator::Instance().GetTDCFromTime(cdh.GetTime(CalTimeType::kNone), kQieRcid);
00760 float sig = cdh.GetCharge(CalDigitType::kSigCorr);
00761 int t = (tdc-tfirst);
00762 int plane = cdh.GetPlexSEIdAltL().GetPlane();
00763 if(plane<121) {
00764 chopHist[ichop]->Fill(t,sig);
00765
00766 chopGraphTdc.push_back(t);
00767 chopGraphPlane.push_back(plane);
00768 chopGraphE.push_back(sig);
00769 chopGraphChop.push_back(ichop);
00770 chopNGraph[ichop]++;
00771 }
00772 }
00773 }
00774
00775
00776 std::vector<TH1*> refSliceHist(refSliceList.size());
00777 std::vector<TH1*> refSliceHistInt(refSliceList.size());
00778 std::vector<float> refSliceGraphTdc;
00779 std::vector<float> refSliceGraphPlane;
00780 std::vector<float> refSliceGraphE;
00781 std::vector<int> refSliceGraphSlice;
00782 std::vector<UInt_t> refSliceNGraph(refSliceList.size(),0);
00783
00784 for(UInt_t ichop = 0;ichop < refSliceList.size(); ichop++) {
00785 refSliceHist[ichop] = new TH1F(Form("refchp_%d",ichop),
00786 Form("Hits RefSlice:%d",ichop),
00787 600, 0, 600);
00788 refSliceHistInt[ichop] = new TH1F(Form("refchpint_%d",ichop),
00789 Form("Hits RefSlice:%d ",ichop),
00790 600, 0, 600);
00791 fCleanup.push_back(refSliceHist[ichop]);
00792 fCleanup.push_back(refSliceHistInt[ichop]);
00793
00794 for(UInt_t idig = 0; idig < refSliceList[ichop].size(); idig++) {
00795 CandDigitHandle cdh = refSliceList[ichop][idig];
00796 int tdc = Calibrator::Instance().GetTDCFromTime(cdh.GetTime(CalTimeType::kNone), kQieRcid);
00797 float sig = cdh.GetCharge(CalDigitType::kSigCorr);
00798 int t = (tdc-tfirst);
00799 int plane = cdh.GetPlexSEIdAltL().GetPlane();
00800 if(plane<121) {
00801 refSliceHist[ichop]->Fill(t,sig);
00802
00803 refSliceGraphTdc.push_back(t);
00804 refSliceGraphPlane.push_back(plane);
00805 refSliceGraphE.push_back(sig);
00806 refSliceGraphSlice.push_back(ichop);
00807 refSliceNGraph[ichop]++;
00808 }
00809 }
00810 }
00811
00812
00813 std::vector<int> chpRank;
00814 TimeRankHistos(chopHist.size(),chopHist, chpRank);
00815 for(UInt_t i = 0; i< chopHist.size(); i++) {
00816 for(UInt_t j=i; j<chopHist.size(); j++) {
00817 chopHistInt[i]->Add(chopHist[j]);
00818 }
00819 int color = (chpRank[i] % 7) + 1;
00820 chopHist[i] -> SetLineColor(color);
00821 chopHist[i] -> SetFillColor(color);
00822 chopHistInt[i] -> SetLineColor(color);
00823 chopHistInt[i] -> SetFillColor(color);
00824 }
00825
00826 std::vector<int> refChpRank;
00827 TimeRankHistos(refSliceHist.size(),refSliceHist, refChpRank);
00828 for(UInt_t i = 0; i< refSliceHist.size(); i++) {
00829 for(UInt_t j=i; j<refSliceHist.size(); j++) {
00830 refSliceHistInt[i]->Add(refSliceHist[j]);
00831 }
00832 int color = (refChpRank[i] % 7) + 1;
00833 refSliceHist[i] -> SetLineColor(color);
00834 refSliceHist[i] -> SetFillColor(color);
00835 refSliceHistInt[i] -> SetLineColor(color);
00836 refSliceHistInt[i] -> SetFillColor(color);
00837 }
00838
00839
00840 std::vector<int> nuRank;
00841 TimeRankHistos(neutrinos.size(), nuHist, nuRank);
00842 for(UInt_t inu = 0; inu< neutrinos.size(); inu++) {
00843
00844 for(UInt_t i=inu; i<nuHist.size(); i++) {
00845 nuHistInt[inu]->Add(nuHist[i]);
00846 }
00847 int color = (nuRank[inu] % 7) +1;
00848 nuHist[inu] -> SetLineColor(color);
00849 nuHist[inu] -> SetFillColor(color);
00850 nuHistInt[inu] -> SetLineColor(color);
00851 nuHistInt[inu] -> SetFillColor(color);
00852 }
00853
00854
00855 std::vector<TGraph*> chopGraphs;
00856 for(UInt_t ichop=0;ichop<chopList.size();ichop++) {
00857 int n = chopNGraph[ichop];
00858 if(n>0) {
00859 TGraph* g = new TGraph(n);
00860 fCleanup.push_back(g);
00861 chopGraphs.push_back(g);
00862 g->SetMarkerStyle(20);
00863 g->SetMarkerColor((chpRank[ichop] % 7) +1);
00864
00865 Int_t i=0;
00866 for(UInt_t p=0;p<chopGraphTdc.size();p++) {
00867 if(chopGraphChop[p] == (int)ichop) {
00868 g->SetPoint(i,chopGraphTdc[p],chopGraphPlane[p]);
00869 i++;
00870 }
00871 }
00872 }
00873 }
00874
00875 std::vector<TGraph*> refSliceGraphs;
00876 for(UInt_t ichop=0;ichop<refSliceList.size();ichop++) {
00877 int n = refSliceNGraph[ichop];
00878 if(n>0) {
00879 TGraph* g = new TGraph(n);
00880 fCleanup.push_back(g);
00881 refSliceGraphs.push_back(g);
00882 g->SetMarkerStyle(20);
00883 g->SetMarkerColor((refChpRank[ichop] % 7) +1);
00884 Int_t i=0;
00885 for(UInt_t p=0;p<refSliceGraphTdc.size();p++) {
00886 if(refSliceGraphSlice[p] == (int)ichop) {
00887 g->SetPoint(i,refSliceGraphTdc[p],refSliceGraphPlane[p]);
00888 i++;
00889 }
00890 }
00891 }
00892 }
00893
00894 std::vector<TGraph*> nuGraphs;
00895 for(UInt_t inu=0;inu<neutrinos.size();inu++) {
00896 int n = nuNGraph[inu];
00897 if(n>0) {
00898 TGraph* g = new TGraph(n);
00899 fCleanup.push_back(g);
00900 nuGraphs.push_back(g);
00901 g->SetMarkerStyle(20);
00902 g->SetMarkerColor((nuRank[inu] % 7) +1);
00903 Int_t i=0;
00904 for(UInt_t p=0;p<nuGraphTdc.size();p++) {
00905 if(nuGraphNu[p] == (int)inu) {
00906 g->SetPoint(i,nuGraphTdc[p],nuGraphPlane[p]);
00907 i++;
00908 }
00909 }
00910 }
00911 }
00912
00913
00914
00915 gStyle->SetOptStat(0);
00916
00917 if(!fCanvas1) fCanvas1 = new TCanvas("TimeCanvas","Time Histograms");
00918 fCanvas1->cd();
00919 fCanvas1->Clear();
00920 fCanvas1->SetLogy(1);
00921 fCanvas1->Divide(1,3,0.001,0.001,kWhite);
00922
00923 fCanvas1->cd(1);
00924 fCanvas1->GetPad(1)->SetLogy(1);
00925 hitHist->Draw();
00926 for(UInt_t i = 0; i < nuHistInt.size(); i++) {
00927 if(nuHistInt[i]->GetEntries()>0) nuHistInt[i]->Draw("same");
00928 }
00929
00930 fCanvas1->cd(2);
00931 fCanvas1->GetPad(2)->SetLogy(1);
00932 hitHist->Draw();
00933 for(UInt_t i = 0;i <chopHistInt.size(); i++) {
00934 if(chopHistInt[i]->GetEntries()>0) chopHistInt[i]->Draw("same");
00935 }
00936
00937 fCanvas1->cd(3);
00938 fCanvas1->GetPad(3)->SetLogy(1);
00939 hitHist->Draw();
00940 for(UInt_t i = 0;i < refSliceHistInt.size(); i++) {
00941 if(refSliceHistInt[i]->GetEntries()>0) refSliceHistInt[i]->Draw("same");
00942 }
00943
00944
00945 if(!fCanvas2) fCanvas2 = new TCanvas("WholeCanvas","Whole Event");
00946 fCanvas2->Clear();
00947 fCanvas2->Divide(1,3,0.001,0.001,kWhite);
00948 fCanvas2->cd(1);
00949 hit2Hist->Draw("colz");
00950 fCanvas2->cd(2);
00951 hitUHist->Draw("colz");
00952 fCanvas2->cd(3);
00953 hitVHist->Draw("colz");
00954
00955
00956 if(!fCanvas3) fCanvas3 = new TCanvas("PosTimeCanvas","Position vs Time");
00957 fCanvas3->cd();
00958 fCanvas3->Clear();
00959 fCanvas3->Divide(1,3,0.001,0.001,kWhite);
00960 TH2* h2frame = new TH2F("h2frame","Plane vs Time",600,0,600,130,0,130);
00961 fCleanup.push_back(h2frame);
00962
00963
00964 fCanvas3->cd(1);
00965 h2frame->Draw();
00966 for(UInt_t i=0;i<nuGraphs.size();i++) {
00967 nuGraphs[i]->Draw("p");
00968 }
00969
00970 fCanvas3->cd(2);
00971 h2frame->Draw();
00972 for(UInt_t i=0;i<chopGraphs.size();i++) {
00973 chopGraphs[i]->Draw("p");
00974 }
00975
00976 fCanvas3->cd(3);
00977 h2frame->Draw();
00978 for(UInt_t i=0;i<refSliceGraphs.size();i++) {
00979 refSliceGraphs[i]->Draw("p");
00980 }
00981
00982
00983
00984 }
00985
00986 {
00987 fFile->cd();
00988 fTree->AutoSave("SaveSelf Overwrite");
00989 fNuTree->AutoSave("SaveSelf Overwrite");
00990 }
00991
00992 if(oldDir) oldDir->cd();
00993 return JobCResult::kPassed;
00994 }
00995
00996
00997
00998 const Registry& ChopModule::DefaultConfig() const
00999 {
01000
01001
01002
01003 static Registry r;
01004
01005
01006 std::string name = this->JobCModule::GetName();
01007 name += ".config.default";
01008 r.SetName(name.c_str());
01009
01010
01011 r.UnLockValues();
01012 r.Set("ChopAlgorithm","AlgChopListFar");
01013 r.Set("ChopAlgConfig","default");
01014 r.Set("ListIn", "canddigitlist");
01015 r.Set("ListOut", "candchoplist");
01016
01017 r.Set("plots",1);
01018 r.Set("eval_sr",0);
01019 r.Set("filename","mychopper.root");
01020 r.Set("particleTimeout",100e-9);
01021
01022 r.LockValues();
01023
01024 return r;
01025 }
01026