00001
00002
00003
00004
00005
00006 #include <iomanip>
00007 #include <set>
00008 #include "TROOT.h"
00009 #include "TObjectTable.h"
00010 #include "MINF_Classes/MINFast.h"
00011 #include "CandData/CandRecord.h"
00012 #include "CandData/CandHeader.h"
00013 #include "CalDetSI/CandCalDetSIHandle.h"
00014 #include "CandDigit/CandDigitListHandle.h"
00015 #include "CandDigit/CandDigitHandle.h"
00016 #include "REROOT_Classes/REROOT_Event.h"
00017 #include "REROOT_Classes/REROOT_FLSDigit.h"
00018 #include "REROOT_Classes/REROOT_StdHep.h"
00019 #include "RerootExodus/RerootExodus.h"
00020 #include "Plex/PlexStripEndId.h"
00021 #include "Plex/PlexSEIdAltLItem.h"
00022 #include "Plex/PlexHandle.h"
00023 #include "Plex/PlexPixelSpotId.h"
00024 #include "UgliGeometry/UgliGeomHandle.h"
00025 #include "Navigation/NavSet.h"
00026 #include "Conventions/CalDigitType.h"
00027 #include "Conventions/CalTimeType.h"
00028 #include "Conventions/Munits.h"
00029 #include "Conventions/ReadoutType.h"
00030 #include "Calibrator/Calibrator.h"
00031 #include "MinosObjectMap/MomNavigator.h"
00032 #include "CandNtupleSR/NtpSRRecord.h"
00033 #include "JobControl/JobCResult.h"
00034 #include "JobControl/JobCModuleRegistry.h"
00035 #include "JobControl/JobCommand.h"
00036 #include "MessageService/MsgService.h"
00037 #include "RecoBase/CandTrackListHandle.h"
00038 #include "RecoBase/CandTrackHandle.h"
00039 #include "RecoBase/CandStripListHandle.h"
00040 #include "RecoBase/CandStripHandle.h"
00041 #include "RecoBase/CandSliceListHandle.h"
00042 #include "RecoBase/CandSliceHandle.h"
00043 #include "RecoBase/CandShowerListHandle.h"
00044 #include "RecoBase/CandShowerHandle.h"
00045 #include "RecoBase/CandEventListHandle.h"
00046 #include "RecoBase/CandEventHandle.h"
00047 #include "RecoBase/LinearFit.h"
00048 #include "RecoBase/PropagationVelocity.h"
00049 #include "CandTrackSR/CandTrackSRHandle.h"
00050 #include "CandTrackSR/CandTrackSRListHandle.h"
00051 #include "CandFitTrackSR/CandFitTrackSRHandle.h"
00052 #include "CandNtupleSR/NtpSRTrack.h"
00053 #include "CandNtupleSR/NtpSRFiducial.h"
00054 #include "CandNtupleSR/NtpSRVertex.h"
00055 #include "CandNtupleSR/NtpSREvent.h"
00056 #include "CandNtupleSR/NtpSRShower.h"
00057 #include "CalDetSI/Helpers.h"
00058 #include "CalDetDST/UberHit.h"
00059 #include "CalDetDST/UberRecordLite.h"
00060 #include "CalDetDST/UberRecHeader.h"
00061 #include "CalDetDST/UberMC.h"
00062 #include "CalDetDST/UberModuleLite.h"
00063
00064 #include "DatabaseInterface/DbiResultPtr.h"
00065 #include "CalDetPID/CalDetBeamMomentum.h"
00066 #include "Calibrator/CalTempCalibration.h"
00067 #include "CalDetPID/CandCalDetPIDHandle.h"
00068 #include "CalDetPID/NtpCalDetPID.h"
00069
00070 #include "Record/SimSnarlRecord.h"
00071 #include "TParticle.h"
00072
00073 #include <cmath>
00074
00075 CVSID("$Id: UberModuleLite.cxx,v 1.19 2007/11/11 09:11:39 rhatcher Exp $");
00076 JOBMODULE(UberModuleLite, "UberModuleLite", "A CalDet ntuple, based on NtupleBase");
00077
00078 using namespace std;
00079
00080 Int_t UberModuleLite::MakePlaneStripIndex(Int_t plane, Int_t strip)
00081 {
00082
00083 return plane*200 + strip;
00084
00085 }
00086
00087
00088
00089
00090 UberModuleLite::UberModuleLite():
00091 fIsMC(kFALSE),
00092 fFirstEvent(kTRUE),
00093 fMCDecision(kFALSE),
00094 fRunNumber(0),
00095 fStarttime(0),
00096 candrec(0),
00097 fCDLH(0),
00098 fCDSI(0),
00099 fStripUidMap(),
00100 fShowerUidMap(),
00101 fTrackUidMap(),
00102 fEventUidMap()
00103 {
00104
00105
00106 MSG("UberModuleLite",Msg::kDebug)<<"In UberModuleLite creator"<<endl;
00107
00108 }
00109
00110
00111 UberModuleLite::~UberModuleLite()
00112 {
00113 MSG("UberModuleLite",Msg::kDebug)<<"In ~UberModuleLite"<<endl;
00114 }
00115
00116
00117 JobCResult UberModuleLite::Get(MomNavigator* mom)
00118 {
00119 MSG("UberModuleLite",Msg::kDebug)<<"In UberModuleLite get"<<endl;
00120
00121
00122 assert(mom);
00123
00124
00125 candrec=dynamic_cast<CandRecord*>
00126 (mom->GetFragment("CandRecord","PrimaryCandidateRecord"));
00127 if(candrec==0){
00128 MSG("UberModuleLite",Msg::kError)<<"candrec==0"<<endl;
00129 return JobCResult(JobCResult::kFailed);
00130 }
00131 if(fRunNumber==0){
00132 const CandHeader *ch = candrec->GetCandHeader();
00133 if(ch!=0){
00134 fRunNumber=ch->GetRun();
00135 MSG("UberModuleLite",Msg::kDebug)<<"RUN NUMBER "<<fRunNumber<<endl;
00136 }
00137 }
00138
00139 fCDLH = dynamic_cast<CandDigitListHandle *>
00140 (candrec->FindCandHandle("CandDigitListHandle","canddigitlist"));
00141 if(fCDLH == 0) {
00142 MSG("UberModuleLite",Msg::kError)<<"fCDLH==0"<<endl;
00143 return JobCResult(JobCResult::kFailed);
00144 }
00145
00146
00147 fCDSI = dynamic_cast<CandCalDetSIHandle *>
00148 (candrec->FindCandHandle("CandCalDetSIHandle"));
00149 if(fCDSI == 0) {
00150 MSG("UberModuleLite",Msg::kError)<<"fCDSI==0"<<endl;
00151 return JobCResult(JobCResult::kFailed);
00152 }
00153
00154
00155 MSG("UberModuleLite",Msg::kDebug)<<"Returning kPassed"<<endl;
00156
00157 return JobCResult(JobCResult::kPassed);
00158 }
00159
00160 JobCResult UberModuleLite::Reco(MomNavigator *mom)
00161 {
00162 MSG("UberModuleLite",Msg::kDebug)<<"In UberModuleLite Reco"<<endl;
00163
00164
00165 CandDigitHandleItr hi(fCDLH->GetDaughterIterator());
00166 if(!hi.IsValid()){
00167 MSG("UberModuleLite",Msg::kError)<<"DaugherIter not valid"<<endl;
00168 return JobCResult(JobCResult::kFailed);
00169 }
00170
00171
00172 const VldContext *vc = (*hi)->GetVldContext();
00173 PlexHandle ph(*vc, kTRUE);
00174 if(!fMCDecision){
00175 if(vc->GetSimFlag()==SimFlag::kReroot||vc->GetSimFlag()==SimFlag::kMC){
00176 fIsMC = kTRUE;
00177 }
00178 fMCDecision = kTRUE;
00179 }
00180
00181 Calibrator::Instance().Reset(*vc);
00182
00183
00184 UberRecHeader newHdr(*vc);
00185 newHdr.SetRunNo(fRunNumber);
00186 if(fFirstEvent){
00187 fStarttime = vc->GetTimeStamp().GetSec();
00188
00189 fFirstEvent=kFALSE;
00190 }
00191 newHdr.SetStartTime(fStarttime);
00192
00193
00194 float temp = 100.0;
00195 if(fIsMC){
00196
00197 newHdr.SetTemperature(temp);
00198 }
00199 else{
00200 newHdr.SetTemperature(Calibrator::Instance().GetTemperature());
00201
00202 }
00203
00204
00205 float p = 0.1;
00206 if(fIsMC){
00207
00208
00209 const SimSnarlRecord* simrec=dynamic_cast<const SimSnarlRecord*>
00210 (mom->GetFragment("SimSnarlRecord"));
00211 if(simrec){
00212
00213 const TClonesArray* stdhep = dynamic_cast<const TClonesArray*>
00214 (simrec->FindComponent("TClonesArray", "StdHep"));
00215 if(stdhep){
00216
00217 const TParticle* part=
00218 dynamic_cast<const TParticle*>(stdhep->At(0));
00219 if(part) p = part->P();
00220 }
00221 }
00222 }
00223 else{
00224 DbiResultPtr<CalDetBeamMomentum> cdbm(*vc);
00225 if(cdbm.GetNumRows()==1) p = cdbm.GetRow(0)->GetMomentum();
00226 }
00227 newHdr.SetBeamMomentum(p);
00228
00229
00230 UberRecordLite *snarldata = new UberRecordLite(newHdr);
00231
00232
00233
00234
00235 fStripUidMap.clear();
00236 fShowerUidMap.clear();
00237 fTrackUidMap.clear();
00238 fEventUidMap.clear();
00239
00240
00241
00242
00243 snarldata->triggertime = fCDLH->GetAbsTime();
00244
00245
00246 snarldata->snarlno = fCDSI->GetSnarl();
00247 MSG("UberModuleLite",Msg::kDebug)<<"SNARL NO "<<snarldata->snarlno<<endl;
00248 snarldata->triggerword = fCDSI->GetTrigSource();
00249 snarldata->ceradc[0]=fCDSI->GetKovADC2();
00250 snarldata->ceradc[1]=fCDSI->GetKovADC1();
00251 snarldata->ceradc[2]=fCDSI->GetKovADC3();
00252 snarldata->torbits=fCDSI->GetTriggerORBits();
00253 snarldata->torok=fCDSI->GetTriggerOROK();
00254
00255
00256
00257
00258
00259
00260 if(fCDSI->GetKovTimeStamp2()!=0){
00261 snarldata->certime[0]=fCDSI->GetKovTimeStamp2()
00262 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00263 MSG("UberModuleLite",Msg::kDebug)<<"Kov 2 timestamp "<<fCDSI->GetKovTimeStamp2()
00264 <<" time convert "<<CalDetConstants::FARTIMECONVERT
00265 <<" trigger time "<<snarldata->triggertime
00266 <<" in ns "
00267 <<snarldata->triggertime/Munits::nanosecond
00268 <<endl;
00269 }
00270 if(fCDSI->GetKovTimeStamp1()!=0){
00271 snarldata->certime[1]=fCDSI->GetKovTimeStamp1()
00272 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00273 }
00274 if(fCDSI->GetKovTimeStamp3()!=0){
00275 snarldata->certime[2]=fCDSI->GetKovTimeStamp3()
00276 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00277 }
00278 snarldata->toftdc[0]=fCDSI->GetTofTDC0();
00279 snarldata->toftdc[1]=fCDSI->GetTofTDC1();
00280 snarldata->toftdc[2]=fCDSI->GetTofTDC2();
00281 snarldata->tofadc[0]=fCDSI->GetTofADC0();
00282 snarldata->tofadc[1]=fCDSI->GetTofADC1();
00283 snarldata->tofadc[2]=fCDSI->GetTofADC2();
00284 if(fCDSI->GetTofTimeStamp()!=0){
00285 snarldata->toftime=fCDSI->GetTofTimeStamp()
00286 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00287 MSG("UberModuleLite",Msg::kDebug)<<"tof timestamp "<<fCDSI->GetTofTimeStamp()
00288 <<" time convert "<<CalDetConstants::FARTIMECONVERT
00289 <<setprecision(10)<<" trigger time "
00290 <<snarldata->triggertime
00291 <<" in ns "
00292 <<setprecision(10)
00293 <<snarldata->triggertime/Munits::nanosecond
00294 <<" tof time "<<snarldata->toftime<<endl;
00295
00296 }
00297 if(fCDSI->GetTofADCTimeStamp0()!=0){
00298 snarldata->tofhittime[0]=fCDSI->GetTofADCTimeStamp0()
00299 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00300 }
00301 if(fCDSI->GetTofADCTimeStamp1()!=0){
00302 snarldata->tofhittime[1]=fCDSI->GetTofADCTimeStamp1()
00303 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00304 }
00305 if(fCDSI->GetTofADCTimeStamp2()!=0){
00306 snarldata->tofhittime[2]=fCDSI->GetTofADCTimeStamp2()
00307 *CalDetConstants::FARTIMECONVERT-snarldata->triggertime/Munits::nanosecond;
00308 }
00309
00310
00311
00312 snarldata->triggertime+=vc->GetTimeStamp().GetSec()-fStarttime;
00313 MSG("UberModuleLite",Msg::kDebug)<<"Trigger time "<<snarldata->triggertime<<endl
00314 <<"vld context time "
00315 <<vc->GetTimeStamp().GetSec()<<endl;
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 Bool_t gotsigcorrconv = kFALSE;
00326
00327
00328
00329
00330 set<UShort_t> deadplanemap;
00331 vector<RawChannelId>::const_iterator dcit(fCDSI->GetDeadChips().begin());
00332 MSG("UberModuleLite", Msg::kDebug)<<"Starting to get dead chip vector"<<endl
00333 <<"Size of Dead Chip vector "
00334 <<fCDSI->GetDeadChips().size()<<endl;
00335 while(dcit!=fCDSI->GetDeadChips().end()){
00336
00337
00338 RawChannelId newid;
00339 newid.SetDetector((*dcit).GetDetector());
00340 newid.SetElecType((*dcit).GetElecType());
00341 newid.SetCrate((*dcit).GetCrate());
00342 if((*dcit).GetElecType()==ElecType::kVA){
00343 newid.SetVarcId((*dcit).GetVarcId());
00344 newid.SetVmm((*dcit).GetVmm());
00345 newid.SetVaAdcSel((*dcit).GetVaAdcSel());
00346 newid.SetVaChip((*dcit).GetVaChip());
00347 newid.SetVaChannel(3);
00348 }
00349 if((*dcit).GetElecType()==ElecType::kQIE){
00350 newid.SetGeographicAddress((*dcit).GetGeographicAddress());
00351 newid.SetMasterChannel((*dcit).GetMasterChannel());
00352 newid.SetMinderChannel((*dcit).GetMinderChannel());
00353 }
00354
00355 newid.SetPedMode(false);
00356 newid.SetSparsMode(false);
00357 newid.SetCommonMode(false);
00358
00359
00360
00361 if(ph.GetSEIdAltL(newid).GetPlane()>=0){
00362 deadplanemap.insert(ph.GetSEIdAltL(newid).GetPlane());
00363 }
00364 if(newid.GetElecType()==ElecType::kVA){
00365 if(fCDSI->GetCerenkovChannel3().GetElecType()==ElecType::kVA){
00366 if(newid.IsSameVAChip(fCDSI->GetCerenkovChannel3())){
00367 deadplanemap.insert(65);
00368 }
00369 }
00370 if(fCDSI->GetCerenkovChannel1().GetElecType()==ElecType::kVA){
00371 if(newid.IsSameVAChip(fCDSI->GetCerenkovChannel1())){
00372 deadplanemap.insert(66);
00373 }
00374 }
00375 if(fCDSI->GetCerenkovChannel2().GetElecType()==ElecType::kVA){
00376 if(newid.IsSameVAChip(fCDSI->GetCerenkovChannel2())){
00377 deadplanemap.insert(67);
00378 }
00379 }
00380 }
00381 else if(newid.GetElecType()==ElecType::kQIE){
00382 if(fCDSI->GetCerenkovChannel3().GetElecType()==ElecType::kQIE){
00383 if(newid.IsSameChannel(fCDSI->GetCerenkovChannel3())){
00384 deadplanemap.insert(65);
00385 }
00386 }
00387 if(fCDSI->GetCerenkovChannel1().GetElecType()==ElecType::kQIE){
00388 if(newid.IsSameChannel(fCDSI->GetCerenkovChannel1())){
00389 deadplanemap.insert(66);
00390 }
00391 }
00392 if(fCDSI->GetCerenkovChannel2().GetElecType()==ElecType::kQIE){
00393 if(newid.IsSameChannel(fCDSI->GetCerenkovChannel2())){
00394 deadplanemap.insert(67);
00395 }
00396 }
00397 }
00398
00399
00400
00401
00402 RawChannelId newid2;
00403 newid2.SetDetector((*dcit).GetDetector());
00404 newid2.SetElecType((*dcit).GetElecType());
00405 newid2.SetCrate((*dcit).GetCrate());
00406 if((*dcit).GetElecType()==ElecType::kVA){
00407 newid2.SetVarcId((*dcit).GetVarcId());
00408 newid2.SetVmm((*dcit).GetVmm());
00409 newid2.SetVaAdcSel((*dcit).GetVaAdcSel());
00410 newid2.SetVaChip((*dcit).GetVaChip());
00411 newid2.SetVaChannel(11);
00412 }
00413 if((*dcit).GetElecType()==ElecType::kQIE){
00414 newid2.SetGeographicAddress((*dcit).GetGeographicAddress());
00415 newid2.SetMasterChannel((*dcit).GetMasterChannel()+1);
00416 newid2.SetMinderChannel((*dcit).GetMinderChannel());
00417 }
00418
00419 newid2.SetPedMode(false);
00420 newid2.SetSparsMode(false);
00421 newid2.SetCommonMode(false);
00422
00423
00424 if(ph.GetSEIdAltL(newid2).GetPlane()>=0){
00425 deadplanemap.insert(ph.GetSEIdAltL(newid2).GetPlane());
00426 }
00427 if((*dcit).GetElecType()==ElecType::kQIE){
00428 RawChannelId newid3;
00429 newid3.SetDetector((*dcit).GetDetector());
00430 newid3.SetElecType((*dcit).GetElecType());
00431 newid3.SetCrate((*dcit).GetCrate());
00432 newid3.SetElecType((*dcit).GetElecType());
00433 newid3.SetGeographicAddress((*dcit).GetGeographicAddress());
00434 newid3.SetMasterChannel((*dcit).GetMasterChannel()+2);
00435 newid3.SetMinderChannel((*dcit).GetMinderChannel());
00436
00437 newid3.SetPedMode(false);
00438 newid3.SetSparsMode(false);
00439 newid3.SetCommonMode(false);
00440
00441
00442 if(ph.GetSEIdAltL(newid3).GetPlane()>=0){
00443 deadplanemap.insert(ph.GetSEIdAltL(newid3).GetPlane());
00444 }
00445 RawChannelId newid4;
00446 newid4.SetDetector((*dcit).GetDetector());
00447 newid4.SetElecType((*dcit).GetElecType());
00448 newid4.SetCrate((*dcit).GetCrate());
00449 newid4.SetElecType((*dcit).GetElecType());
00450 newid4.SetGeographicAddress((*dcit).GetGeographicAddress());
00451 newid4.SetMasterChannel((*dcit).GetMasterChannel()+3);
00452 newid4.SetMinderChannel((*dcit).GetMinderChannel());
00453
00454 newid4.SetPedMode(false);
00455 newid4.SetSparsMode(false);
00456 newid4.SetCommonMode(false);
00457
00458
00459 if(ph.GetSEIdAltL(newid4).GetPlane()>=0){
00460 deadplanemap.insert(ph.GetSEIdAltL(newid4).GetPlane());
00461 }
00462 }
00463
00464
00465 dcit++;
00466 }
00467 if(deadplanemap.size()!=0){
00468 snarldata->mindeadplaneno = *(deadplanemap.begin());
00469 snarldata->ndeadplanes = deadplanemap.size();
00470 }
00471 MSG("UberModuleLite",Msg::kDebug)<<"First dead plane "<<snarldata->mindeadplaneno
00472 <<" No. dead planes "<<snarldata->ndeadplanes<<endl;
00473
00474
00475
00476
00477 CandDigitHandleKeyFunc* kf = hi.CreateKeyFunc();
00478 kf->SetFun(CalHelpers::KeyFromPlane);
00479 hi.GetSet()->AdoptSortKeyFunc(kf,kTRUE,kFALSE);
00480
00481 kf=hi.CreateKeyFunc();
00482 kf->SetFun(CalHelpers::KeyFromStrip);
00483 hi.GetSet()->AdoptSortKeyFunc(kf,kFALSE,kFALSE);
00484
00485 kf=hi.CreateKeyFunc();
00486 kf->SetFun(CalHelpers::KeyFromEnd);
00487 hi.GetSet()->AdoptSortKeyFunc(kf,kFALSE,kTRUE);
00488 kf = 0;
00489 MSG("UberModuleLite",Msg::kDebug)<<"Done sorting"<<endl;
00490
00491
00492 Float_t maxplanemip = 0.;
00493 Float_t maxp0stripmip=0.;
00494 Float_t maxp1stripmip=0.;
00495 Float_t maxp0hitmip=0.;
00496 Float_t maxp1hitmip=0.;
00497 Float_t totmipeven=0.;
00498 Float_t totmipodd=0.;
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 MSG("UberModuleLite",Msg::kDebug)<<"begining to loop over hits"<<endl;;
00539 for(hi.Reset();hi.IsValid();hi.NextKey()){
00540 UShort_t plane = (*hi)->GetPlexSEIdAltL().GetPlane();
00541 MSG("UberModuleLite",Msg::kDebug)<<"PLANE "<<plane<<endl;
00542 Bool_t iscosmic = kFALSE;
00543 if(plane>=CalDetConstants::PLANECONST){
00544 iscosmic=kTRUE;
00545 }
00546 if(!iscosmic){
00547 snarldata->nhitplanes++;
00548 }
00549 Float_t planemip=0.;
00550
00551
00552 for(CandDigitHandleItr siter(hi, kTRUE);
00553 siter.IsValid();siter.NextKey()){
00554 UShort_t strip = (*siter)->GetPlexSEIdAltL().GetBestSEId().GetStrip();
00555 MSG("UberModuleLite",Msg::kDebug)<<"STRIP "<<strip<<endl;
00556 if(!iscosmic){
00557 MSG("UberModuleLite",Msg::kDebug)<<"adding one to nhitstrips"<<endl;
00558 snarldata->nhitstrips++;
00559 MSG("UberModuleLite",Msg::kDebug)<<"adding next hit to tclonesarray"<<endl;
00560
00561 int sindx = snarldata->AddNextHit(plane,strip);
00562 MSG("UberModuleLite",Msg::kDebug)<<"added next hit to tclonesarray"<<endl;
00563
00564 Int_t uid = MakePlaneStripIndex(plane, strip);
00565 fStripUidMap.insert(std::make_pair(uid,sindx));
00566
00567
00568
00569
00570
00571
00572 }
00573 if(iscosmic){
00574 snarldata->AddNextCosmicHit(plane,strip);
00575 }
00576 Float_t p0stripmip=0.;
00577 Float_t p1stripmip=0.;
00578
00579
00580 for(CandDigitHandleItr eiter(siter,kTRUE);
00581 eiter.IsValid();eiter.Next()){
00582
00583 MSG("UberModuleLite",Msg::kDebug)<<"RAW CHANNEL ID FOR THIS TIME ROUND:"<<endl;
00584
00585 MSG("UberModuleLite",Msg::kDebug)<<endl;
00586
00587 MSG("UberModuleLite",Msg::kDebug)<<" readouttype "
00588 <<ph.GetReadoutType((*eiter)->GetChannelId())
00589 <<endl;
00590
00591 if(((*eiter)->GetPlexSEIdAltL()).size()!=1){
00592 MSG("UberModuleLite",Msg::kDebug)<<"Wrong size of Plexseidaltl "
00593 <<((*eiter)->GetPlexSEIdAltL()).size()
00594 <<" snarl no "<<snarldata->snarlno
00595 <<" plane is "<<plane<<endl;
00596 }
00597 if((*eiter)->GetPlexSEIdAltL().size()<=0){
00598 MSG("UberModuleLite",Msg::kDebug)<<"plexseidaltl is EMPTY"<<endl;
00599
00600
00601
00602
00603 continue;
00604 }
00605
00606
00607
00608
00609
00610
00611 PlexStripEndId pse = (*eiter)->GetPlexSEIdAltL().GetBestSEId();
00612 StripEnd::StripEnd_t se = pse.GetEnd();
00613 PlexSEIdAltLItem pseitem = (*eiter)->GetPlexSEIdAltL().GetBestItem();
00614
00615
00616
00617 Int_t adc = (int)(*eiter)->GetCharge();
00618 Float_t siglin = (*eiter)->GetCharge(CalDigitType::kSigLin);
00619 Float_t npe = pseitem.GetPE();
00620 Float_t sigcorr = (*eiter)->GetCharge(CalDigitType::kSigCorr);
00621 Float_t mip = Calibrator::Instance().GetMIP((*eiter)
00622 ->GetCharge(CalDigitType::kSigCorr),pse);
00623 Float_t time = ((*eiter)->GetSubtractedTime(CalTimeType::kT0)
00624 /Munits::nanosecond);
00625 PlexPixelSpotId pps=ph.GetPixelSpotId(pse);
00626 Int_t agg = pps.GetEncoded();
00627
00628
00629 if(iscosmic){
00630 snarldata->AddNextCosmicHitValues(se, adc, time, agg);
00631 continue;
00632 }
00633
00634 snarldata->nhits++;
00635 if(!gotsigcorrconv){
00636
00637 if(mip>0) snarldata->sigcorrconv = sigcorr/mip;
00638 else snarldata->sigcorrconv=-1;
00639 gotsigcorrconv=kTRUE;
00640 }
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663 snarldata->AddNextHitValues(se, adc, siglin, npe, mip, time, agg);
00664 MSG("UberModuleLite",Msg::kDebug)<<"STRIP END "<<se<<" adc "<<adc<<endl;
00665 planemip+=mip;
00666
00667 if(pse.GetPlane()%2==0){
00668 snarldata->mipweighcentereven+=mip*pse.GetStrip();
00669 totmipeven+=mip;
00670 }
00671 else{
00672 snarldata->mipweighcenterodd+=mip*pse.GetStrip();
00673 totmipodd+=mip;
00674 }
00675
00676
00677 if(adc>snarldata->maxadc){
00678 snarldata->maxadc = adc;
00679 }
00680 if(npe>snarldata->maxnpe){
00681 snarldata->maxnpe = npe;
00682 }
00683 if(mip>snarldata->maxmip){
00684 snarldata->maxmip = mip;
00685 }
00686 if(time>snarldata->maxtime){
00687 snarldata->maxtime = time;
00688 }
00689
00690
00691 if(pse.GetPlane()!=0){
00692 snarldata->totmip+=mip;
00693 }
00694
00695
00696 if(pse.GetPlane()==0){
00697 snarldata->p0totmip+=mip;
00698 p0stripmip+=mip;
00699 if(mip>maxp0hitmip){
00700 maxp0hitmip = mip;
00701 snarldata->p0maxmiptstamp = time;
00702 }
00703 }
00704
00705
00706 if(pse.GetPlane()==1){
00707 snarldata->p1totmip+=mip;
00708 p1stripmip+=mip;
00709 if(mip>maxp1hitmip){
00710 maxp1hitmip = mip;
00711 snarldata->p1maxmiptstamp = time;
00712 }
00713 }
00714 }
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732 if(p0stripmip>maxp0stripmip){
00733 maxp0stripmip = p0stripmip;
00734 snarldata->p0stripmaxmip = strip;
00735 }
00736
00737 if(p1stripmip>maxp1stripmip){
00738 maxp1stripmip = p1stripmip;
00739 snarldata->p1stripmaxmip = strip;
00740 }
00741 }
00742
00743 snarldata->mipweighaveplane+=planemip*plane;
00744 if(planemip>maxplanemip){
00745 maxplanemip = planemip;
00746 snarldata->mipshowermax = maxplanemip;
00747 snarldata->showermax = plane;
00748 }
00749 }
00750
00751 if((snarldata->totmip+snarldata->p0totmip)>0){
00752 snarldata->mipweighaveplane/=(snarldata->totmip
00753 +snarldata->p0totmip);
00754 }
00755 else snarldata->mipweighaveplane=-1;
00756
00757
00758 if(totmipeven>0) snarldata->mipweighcentereven/=totmipeven;
00759 else snarldata->mipweighcentereven=-1;
00760 if(totmipodd>0) snarldata->mipweighcenterodd/=totmipodd;
00761 else snarldata->mipweighcenterodd=-1;
00762
00763
00764
00765 for(hi.Reset();hi.IsValid();hi.NextKey()){
00766 UShort_t plane = ((*hi)->GetPlexSEIdAltL()).GetPlane();
00767 if(plane>=CalDetConstants::PLANECONST){
00768 continue;
00769 }
00770 float center = 0.;
00771 if(plane%2==0){
00772 center=snarldata->mipweighcentereven;
00773 }
00774 else{
00775 center = snarldata->mipweighcenterodd;
00776 }
00777 for(CandDigitHandleItr siter(hi, kTRUE);
00778 siter.IsValid();siter.NextKey()){
00779 for(CandDigitHandleItr eiter(siter,kTRUE);
00780 eiter.IsValid();eiter.Next()){
00781 PlexStripEndId pse = (*eiter)->GetPlexSEIdAltL().GetBestSEId();
00782 if(pse.GetStrip()>=CalDetConstants::STRIPCONST){
00783 continue;
00784 }
00785 Float_t mip = Calibrator::Instance().GetMIP((*eiter)
00786 ->GetCharge(CalDigitType::kSigCorr),pse);
00787
00788 snarldata->mipweighrad += fabs(center-pse.GetStrip())*mip;
00789 }
00790 }
00791 }
00792
00793
00794 if((snarldata->totmip+snarldata->p0totmip)>0.0)
00795 snarldata->mipweighrad/=(snarldata->totmip+snarldata->p0totmip);
00796 else snarldata->mipweighrad=0;
00797
00798 this->FillNtpCalDetPID(snarldata);
00799
00800 this -> FillNtpShower(snarldata);
00801 this -> FillNtpTrack(snarldata);
00802 this -> FillNtpEvent(snarldata);
00803
00804 MSG("UberModuleLite",Msg::kDebug)<<"giving fragment to mom"<<endl;
00805 mom->AdoptFragment(snarldata);
00806
00807
00808 MSG("UberModuleLite",Msg::kDebug)<<"done with this event"<<endl;
00809 return JobCResult(JobCResult::kPassed);
00810 }
00811
00812
00813 void UberModuleLite::FillNtpCalDetPID(UberRecordLite* ntprec)
00814 {
00815 MSG("UberModuleLite",Msg::kVerbose)
00816 << "UberModuleLiteModule::FillNtpCalDetPID" << endl;
00817
00818 const CandCalDetPIDHandle* pidh
00819 = dynamic_cast <const CandCalDetPIDHandle*>
00820 (candrec -> FindCandHandle("CandCalDetPIDHandle"));
00821 if ( !pidh ) return;
00822
00823 if(pidh->NoOverlap()) ntprec->cpid.nov=1;
00824 else ntprec->cpid.nov=0;
00825
00826 if(pidh->InCERTime()) ntprec->cpid.inct=1;
00827 else ntprec->cpid.inct=0;
00828
00829 ntprec->cpid.pid=pidh->GetPIDType();
00830 ntprec->cpid.olchi2=pidh->GetOLChi2();
00831
00832 return;
00833 }
00834
00835 void UberModuleLite::FillNtpShower(UberRecordLite* ntprec)
00836 {
00837
00838
00839
00840
00841
00842
00843
00844
00845 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLiteModule::FillNtpShower" << endl;
00846
00847 const CandShowerListHandle *showerlisthandle
00848 = dynamic_cast <const CandShowerListHandle*>
00849 (candrec -> FindCandHandle("CandShowerListHandle"));
00850 if ( !showerlisthandle ) return;
00851
00852 Int_t nshower = 0;
00853 TIter showerItr(showerlisthandle->GetDaughterIterator());
00854 TClonesArray& showerarray = *(ntprec->shw);
00855 while (CandShowerHandle* shower=dynamic_cast<CandShowerHandle*>
00856 (showerItr())) {
00857 Int_t uid = shower->GetUidInt();
00858 fShowerUidMap.insert(std::make_pair(uid,nshower));
00859
00860 NtpSRShower* ntpshower
00861 = new(showerarray[nshower++])NtpSRShower(shower->GetNStrip());
00862
00863 ntpshower->index = nshower - 1;
00864 ntpshower->ndigit = shower->GetNDigit();
00865 TIter showerstripItr(shower->GetDaughterIterator());
00866 Int_t nshowerstrip = 0;
00867
00868
00869 while (TObject* obj = showerstripItr()) {
00870 CandStripHandle* showerstrip = dynamic_cast<CandStripHandle*>(obj);
00871 if(showerstrip){
00872 Int_t plane = showerstrip->GetPlane();
00873 Int_t strip = showerstrip->GetStrip();
00874
00875 Int_t uid = MakePlaneStripIndex(plane,strip);
00876 Int_t stripindex = fStripUidMap[uid];
00877 ntpshower->AddStripAt(stripindex,nshowerstrip);
00878 nshowerstrip++;
00879 }
00880 }
00881
00882
00883 ntpshower->plane.n = shower->GetNPlane();
00884 ntpshower->plane.nu = shower->GetNPlane(PlaneView::kU);
00885 ntpshower->plane.nv = shower->GetNPlane(PlaneView::kV);
00886 ntpshower->plane.beg = shower->GetBegPlane();
00887 ntpshower->plane.begu = shower->GetBegPlane(PlaneView::kU);
00888 ntpshower->plane.begv = shower->GetBegPlane(PlaneView::kV);
00889 ntpshower->plane.end = shower->GetEndPlane();
00890 ntpshower->plane.endu = shower->GetEndPlane(PlaneView::kU);
00891 ntpshower->plane.endv = shower->GetEndPlane(PlaneView::kV);
00892
00893 ntpshower->ph.raw = shower->GetCharge(CalStripType::kNone);
00894 ntpshower->ph.siglin = shower->GetCharge(CalStripType::kSigLin);
00895 ntpshower->ph.sigcor = shower->GetCharge(CalStripType::kSigCorr);
00896 ntpshower->ph.pe = shower->GetCharge(CalStripType::kPE);
00897 ntpshower->ph.mip = shower->GetCharge(CalStripType::kMIP);
00898 ntpshower->ph.gev = shower->GetCharge(CalStripType::kGeV);
00899
00900 }
00901
00902 return;
00903 }
00904
00905
00906
00907 void UberModuleLite::FillNtpTrack(UberRecordLite* ntprec)
00908 {
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrack" << endl;
00919
00920 const Double_t cos45 = 0.70710678;
00921
00922 const CandTrackListHandle *tracklisthandle
00923 = dynamic_cast <const CandTrackListHandle*>
00924 (candrec -> FindCandHandle("CandFitTrackListHandle"));
00925 if ( !tracklisthandle ) {
00926 tracklisthandle = dynamic_cast <const CandTrackListHandle*>
00927 (candrec -> FindCandHandle("CandTrackListHandle"));
00928 }
00929 if ( !tracklisthandle ) return;
00930
00931 CandTrackSRListHandle* tracksrlisthandle=dynamic_cast<CandTrackSRListHandle*>
00932 (candrec->FindCandHandle("CandTrackSRListHandle"));
00933
00934 const VldContext& vld = *(candrec->GetVldContext());
00935
00936 TIter trackItr(tracklisthandle->GetDaughterIterator());
00937 TClonesArray& trackarray = *(ntprec->trk);
00938 Int_t ntrack = 0;
00939 while (CandTrackHandle* track = dynamic_cast<CandTrackHandle*>(trackItr())){
00940 Int_t uid = track->GetUidInt();
00941 fTrackUidMap.insert(std::make_pair(uid,ntrack));
00942
00943 NtpSRTrack* ntptrack
00944 = new(trackarray[ntrack++])NtpSRTrack(track->GetNStrip());
00945
00946 ntptrack->index = ntrack-1;
00947
00948 CandTrackSRHandle *tracksr = dynamic_cast<CandTrackSRHandle*>(track);
00949
00950 CandFitTrackSRHandle *fittracksr
00951 =dynamic_cast<CandFitTrackSRHandle*>(track);
00952
00953
00954 NtpSRTrackPlane& plane = ntptrack->plane;
00955 plane.n = track->GetNPlane();
00956 plane.nu = track->GetNPlane(PlaneView::kU);
00957 plane.nv = track->GetNPlane(PlaneView::kV);
00958 plane.beg = track->GetBegPlane();
00959 plane.begu = track->GetBegPlane(PlaneView::kU);
00960 plane.begv = track->GetBegPlane(PlaneView::kV);
00961 plane.end = track->GetEndPlane();
00962 plane.endu = track->GetEndPlane(PlaneView::kU);
00963 plane.endv = track->GetEndPlane(PlaneView::kV);
00964 if (tracksr) plane.ntrklike = tracksr->GetNTrackPlane();
00965 if (fittracksr) plane.ntrklike = fittracksr->GetNTrackPlane();
00966
00967
00968 NtpSRStripPulseHeight& ph = ntptrack->ph;
00969 ph.raw = track->GetCharge(CalStripType::kNone);
00970 ph.siglin = track->GetCharge(CalStripType::kSigLin);
00971 ph.sigcor = track->GetCharge(CalStripType::kSigCorr);
00972 ph.pe = track->GetCharge(CalStripType::kPE);
00973 ph.mip = track->GetCharge(CalStripType::kMIP);
00974 ph.gev = track->GetCharge(CalStripType::kGeV);
00975
00976 ntptrack->ds = track->GetdS();
00977 ntptrack->range = track->GetRange();
00978
00979 if (tracksrlisthandle) ntptrack->cputime = tracksrlisthandle->GetCPUTime();
00980
00981 this->FillNtpTrackVertex(ntptrack,track);
00982 this->FillNtpTrackEnd(ntptrack,track);
00983 this->FillNtpTrackLinearFit(ntptrack,track);
00984
00985 this->FillNtpTrackFidVtx(ntptrack,track,vld);
00986 this->FillNtpTrackFidEnd(ntptrack,track,vld);
00987 this->FillNtpTrackFidAll(ntptrack,track,vld);
00988
00989 this->FillNtpTrackMomentum(ntptrack,track);
00990 this->FillNtpTrackFit(ntptrack,track);
00991 this->FillNtpTrackTime(ntptrack,track);
00992
00993
00994 TIter trackstripItr(track->GetDaughterIterator());
00995 Int_t ntrackstrip = 0;
00996
00997
00998
00999 while (TObject* obj = (trackstripItr())) {
01000 CandStripHandle* trackstrip = dynamic_cast<CandStripHandle*>(obj);
01001 if(trackstrip){
01002 Int_t plane = trackstrip->GetPlane();
01003 Int_t strip = trackstrip->GetStrip();
01004 Int_t uid = MakePlaneStripIndex(plane,strip);
01005 Int_t stripindex = fStripUidMap[uid];
01006 ntptrack->AddStripAt(stripindex,ntrackstrip);
01007
01008 Int_t iplane = trackstrip->GetPlane();
01009 ntptrack->stpu[ntrackstrip] = track->GetU(iplane);
01010 ntptrack->stpv[ntrackstrip] = track->GetV(iplane);
01011 ntptrack->stpx[ntrackstrip] = cos45*(ntptrack->stpu[ntrackstrip]
01012 -ntptrack->stpv[ntrackstrip]);
01013 ntptrack->stpy[ntrackstrip] = cos45*(ntptrack->stpu[ntrackstrip]
01014 +ntptrack->stpv[ntrackstrip]);
01015 ntptrack->stpz[ntrackstrip] = track->GetZ(iplane);
01016
01017 ntptrack->stpds[ntrackstrip] = track->GetdS(iplane);
01018
01019
01020 if ( fittracksr ) {
01021 ntptrack->stpfitchi2[ntrackstrip] = fittracksr->GetPlaneChi2(iplane);
01022 ntptrack->stpfitprechi2[ntrackstrip]
01023 = fittracksr->GetPlanePreChi2(iplane);
01024 ntptrack->stpfitqp[ntrackstrip] = fittracksr->GetPlaneQP(iplane);
01025 if ( fittracksr->GetBadFit(iplane) ) ntptrack->stpfit[ntrackstrip] = 0;
01026 }
01027
01028
01029 for (UInt_t i = 0; i < 2; i++ ) {
01030 StripEnd::EStripEnd stripend = StripEnd::kNegative;
01031 if (i == 1) stripend = StripEnd::kPositive;
01032 if ( trackstrip->GetNDigit(stripend) > 0 ) {
01033 Float_t sigmap = track->GetStripCharge(trackstrip,
01034 CalStripType::kSigMapped,stripend);
01035 Float_t mip = track->GetStripCharge(trackstrip,
01036 CalStripType::kMIP,stripend);
01037 Float_t gev = track->GetStripCharge(trackstrip,
01038 CalStripType::kGeV,stripend);
01039 ntptrack->SetPh(sigmap,mip,gev,ntrackstrip,i);
01040 ntptrack->SetTime(track->GetT(iplane,stripend),ntrackstrip,i);
01041 }
01042
01043
01044 float c0 = Calibrator::Instance().DecalStripToStrip(1.0,trackstrip->GetStripEndId(stripend));
01045 ntptrack->SetAttnC0( c0 ,ntrackstrip,i);
01046
01047 float t0 = Calibrator::Instance().DecalTime(0.0,trackstrip->GetCharge(CalDigitType::kNone,stripend),trackstrip->GetStripEndId(stripend));
01048 ntptrack->SetCalT0(t0,ntrackstrip,i);
01049
01050 }
01051 ntrackstrip++;
01052 }
01053 }
01054
01055 }
01056
01057 return;
01058
01059 }
01060
01061
01062
01063 void UberModuleLite::FillNtpEvent(UberRecordLite* ntprec)
01064 {
01065
01066
01067
01068
01069
01070
01071
01072
01073 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpEvent" << endl;
01074
01075 const CandEventListHandle *eventlisthandle
01076 = dynamic_cast <const CandEventListHandle*>
01077 (candrec -> FindCandHandle("CandEventListHandle"));
01078 if ( !eventlisthandle ) return;
01079
01080 Int_t nevent = 0;
01081 TIter eventItr(eventlisthandle->GetDaughterIterator());
01082 TClonesArray& eventarray = *(ntprec->evt);
01083 while (CandEventHandle* event=dynamic_cast<CandEventHandle*>
01084 (eventItr())) {
01085 Int_t uid = event->GetUidInt();
01086 fEventUidMap.insert(std::make_pair(uid,nevent));
01087
01088 NtpSREvent* ntpevent
01089 = new(eventarray[nevent++])NtpSREvent(event->GetNStrip(),
01090 event->GetLastShower()+1,event->GetLastTrack()+1);
01091 ntpevent->index = nevent-1;
01092 ntpevent->ndigit = event->GetNDigit();
01093
01094 TIter eventstripItr(event->GetDaughterIterator());
01095 Int_t neventstrip = 0;
01096
01097 while ( CandStripHandle *eventstrip = dynamic_cast<CandStripHandle*>
01098 (eventstripItr())) {
01099 Int_t stripindex = fStripUidMap[eventstrip->GetUidInt()];
01100 ntpevent->AddStripAt(stripindex,neventstrip);
01101 neventstrip++;
01102 }
01103 for (Int_t i = 0; i <= event->GetLastTrack(); i++ ) {
01104 const CandTrackHandle* track = event->GetTrack(i);
01105 Int_t trackindex = fTrackUidMap[track->GetUidInt()];
01106 ntpevent -> AddTrackAt(trackindex,i);
01107 }
01108 for (Int_t i = 0; i <= event->GetLastShower(); i++ ) {
01109 const CandShowerHandle* shower = event->GetShower(i);
01110 Int_t showerindex = fShowerUidMap[shower->GetUidInt()];
01111 ntpevent -> AddShowerAt(showerindex,i);
01112 }
01113
01114
01115 ntpevent->plane.n = event->GetNPlane();
01116 ntpevent->plane.nu = event->GetNPlane(PlaneView::kU);
01117 ntpevent->plane.nv = event->GetNPlane(PlaneView::kV);
01118 ntpevent->plane.beg = event->GetBegPlane();
01119 ntpevent->plane.begu = event->GetBegPlane(PlaneView::kU);
01120 ntpevent->plane.begv = event->GetBegPlane(PlaneView::kV);
01121 ntpevent->plane.end = event->GetEndPlane();
01122 ntpevent->plane.endu = event->GetEndPlane(PlaneView::kU);
01123 ntpevent->plane.endv = event->GetEndPlane(PlaneView::kV);
01124
01125 ntpevent->ph.raw = event->GetCharge(CalStripType::kNone);
01126 ntpevent->ph.siglin = event->GetCharge(CalStripType::kSigLin);
01127 ntpevent->ph.sigcor = event->GetCharge(CalStripType::kSigCorr);
01128 ntpevent->ph.pe = event->GetCharge(CalStripType::kPE);
01129 ntpevent->ph.mip = event->GetCharge(CalStripType::kMIP);
01130 ntpevent->ph.gev = event->GetCharge(CalStripType::kGeV);
01131 }
01132
01133 return;
01134 }
01135
01136
01137
01138 void UberModuleLite::FillNtpTrackMomentum(NtpSRTrack* ntptrack,
01139 const CandTrackHandle* track) {
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackMomentum" << endl;
01150
01151 NtpSRMomentum& momentum = ntptrack->momentum;
01152 momentum.range = track->GetMomentum();
01153
01154 const CandFitTrackHandle* fittrack
01155 = dynamic_cast<const CandFitTrackHandle*>(track);
01156 if ( fittrack ) {
01157 if(fittrack->GetMomentumCurve())
01158 momentum.qp = fittrack->GetEMCharge()/fittrack->GetMomentumCurve();
01159 else momentum.qp=0;
01160 }
01161
01162 const CandFitTrackSRHandle* fittracksr
01163 = dynamic_cast<const CandFitTrackSRHandle*>(track);
01164 if ( fittracksr ) {
01165 momentum.eqp = fittracksr->GetVtxQPError();
01166 }
01167
01168 return;
01169
01170 }
01171
01172 void UberModuleLite::FillNtpTrackTime(NtpSRTrack* ntptrack,
01173 const CandTrackHandle* track) {
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackTime" << endl;
01184
01185 NtpSRTrackTime& time = ntptrack->time;
01186
01187 const CandTrackSRHandle* tracksr
01188 = dynamic_cast<const CandTrackSRHandle*>(track);
01189 if ( tracksr ) {
01190 time.ndigit = tracksr->GetNTimeFitDigit();
01191 time.chi2 = tracksr->GetTimeFitChi2();
01192 }
01193
01194 const CandFitTrackSRHandle* fittracksr
01195 = dynamic_cast<const CandFitTrackSRHandle*>(track);
01196 if ( fittracksr ) {
01197 time.ndigit = fittracksr->GetNTimeFitDigit();
01198 time.chi2 = fittracksr->GetTimeFitChi2();
01199 }
01200
01201 time.cdtds = fabs(track->GetTimeSlope())*3.e8;
01202 time.dtds = track->GetTimeSlope();
01203 time.t0 = track->GetTimeOffset();
01204
01205 Double_t totuph[2] = {0}, totvph[2] = {0};
01206 Int_t ndutimespace[1000] = {0}, ndvtimespace[1000] = {0};
01207 Double_t dutimespace[1000] = {0}, dvtimespace[1000] = {0};
01208
01209 TIter trackstripItr(track->GetDaughterIterator());
01210 while (CandStripHandle* trackstrip = dynamic_cast<CandStripHandle*>
01211 (trackstripItr())) {
01212 Int_t iplane = trackstrip -> GetPlane();
01213 assert(iplane >= 0 && iplane < 1000);
01214 Float_t ph0 = trackstrip -> GetCharge(StripEnd::kNegative);
01215 Float_t ph1 = trackstrip -> GetCharge(StripEnd::kPositive);
01216 Float_t t0 = track->GetT(iplane,StripEnd::kNegative);
01217 Float_t t1 = track->GetT(iplane,StripEnd::kPositive);
01218
01219 if ( trackstrip -> GetPlaneView() == PlaneView::kU ) {
01220 if ( trackstrip -> GetNDigit(StripEnd::kNegative) > 0 ) {
01221 totuph[0] += ph0;
01222 time.u0 += ph0*t0;
01223 }
01224 if ( trackstrip -> GetNDigit(StripEnd::kPositive) > 0 ) {
01225 totuph[1] += ph1;
01226 time.u1 += ph1*t1;
01227 }
01228 if ( t0 > 0 && t1 > 0 ) {
01229 Float_t dapos = .5*(t0-t1)*PropagationVelocity::VelocityPosErr();
01230 if (!ndutimespace[iplane] || fabs(dapos)<fabs(dutimespace[iplane])) {
01231 dutimespace[iplane] = dapos;
01232 ndutimespace[iplane] = 1;
01233 }
01234 }
01235 }
01236
01237 if ( trackstrip -> GetPlaneView() == PlaneView::kV ) {
01238 if ( trackstrip -> GetNDigit(StripEnd::kNegative) > 0 ) {
01239 totvph[0] += ph0;
01240 time.v0 += ph0*t0;
01241 }
01242 if ( trackstrip -> GetNDigit(StripEnd::kPositive) > 0 ) {
01243 totvph[1] += ph1;
01244 time.v1 += ph1*t1;
01245 }
01246 if ( trackstrip -> GetNDigit(StripEnd::kNegative) > 0 &&
01247 trackstrip -> GetNDigit(StripEnd::kPositive) > 0 ) {
01248 Float_t dapos = .5*(t0-t1)*PropagationVelocity::VelocityPosErr();
01249 if (!ndvtimespace[iplane]||fabs(dapos) < fabs(dvtimespace[iplane])) {
01250 dvtimespace[iplane] = dapos;
01251 ndvtimespace[iplane] = 1;
01252 }
01253 }
01254 }
01255 }
01256
01257 Int_t ndu = 0;
01258 Int_t ndv = 0;
01259 for (int ip = 0; ip < 1000; ip++ ) {
01260 if ( ndutimespace[ip] > 0 ) {
01261 ndu++;
01262 time.du += dutimespace[ip];
01263 }
01264 if ( ndvtimespace[ip] > 0 ) {
01265 ndv++;
01266 time.dv += dvtimespace[ip];
01267 }
01268 }
01269 if ( totuph[0] > 0. ) time.u0 /= totuph[0];
01270 if ( totvph[0] > 0. ) time.v0 /= totvph[0];
01271 if ( totuph[1] > 0. ) time.u1 /= totuph[1];
01272 if ( totvph[1] > 0. ) time.v1 /= totvph[1];
01273 if ( ndu ) time.du /= (Float_t)ndu;
01274 if ( ndv ) time.dv /= (Float_t)ndv;
01275
01276 return;
01277
01278 }
01279
01280 void UberModuleLite::FillNtpTrackFit(NtpSRTrack* ntptrack,
01281 const CandTrackHandle* track) {
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackFit" << endl;
01292
01293 NtpSRFitTrack& fit = ntptrack->fit;
01294
01295 const CandFitTrackHandle* fittrack
01296 = dynamic_cast<const CandFitTrackHandle*>(track);
01297 if ( fittrack ) {
01298 fit.chi2 = fittrack->GetChi2();
01299 fit.pass = fittrack->GetPass();
01300 }
01301
01302 const CandFitTrackSRHandle* fittracksr
01303 = dynamic_cast<const CandFitTrackSRHandle*>(track);
01304 if ( fittracksr ) {
01305 fit.ndof = fittracksr->GetNDOF();
01306 fit.niterate = fittracksr->GetNIterate();
01307 fit.nswimfail = fittracksr->GetNSwimFail();
01308 fit.cputime = fittracksr->GetCPUTime();
01309 }
01310
01311 return;
01312
01313 }
01314
01315 void UberModuleLite::FillNtpTrackFidVtx(NtpSRTrack* ntptrack,
01316 const CandTrackHandle* track,
01317 const VldContext& vld) {
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackFidVtx" << endl;
01329
01330 NtpSRFiducial& fid = ntptrack->fidvtx;
01331 NtpSRVertex& vtx = ntptrack->vtx;
01332
01333 this->FillNtpFiducial(fid,vtx,vld);
01334
01335 fid.trace = track->GetVtxTrace();
01336 fid.tracez = track->GetVtxTraceZ();
01337
01338 const CandFitTrackSRHandle* fittracksr
01339 = dynamic_cast<const CandFitTrackSRHandle*>(track);
01340 if ( fittracksr ) {
01341 fid.nplane = fittracksr->GetVtxExtrapolate();
01342
01343
01344 }
01345
01346 return;
01347
01348 }
01349
01350 void UberModuleLite::FillNtpTrackFidEnd(NtpSRTrack* ntptrack,
01351 const CandTrackHandle* track,
01352 const VldContext& vld) {
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackFidEnd" << endl;
01364
01365 NtpSRFiducial& fid = ntptrack->fidend;
01366 NtpSRVertex& end = ntptrack->end;
01367
01368 this->FillNtpFiducial(fid,end,vld);
01369
01370 fid.trace = track->GetEndTrace();
01371 fid.tracez = track->GetEndTraceZ();
01372
01373 const CandFitTrackSRHandle* fittracksr
01374 = dynamic_cast<const CandFitTrackSRHandle*>(track);
01375 if ( fittracksr ) {
01376 fid.nplane = fittracksr->GetEndExtrapolate();
01377
01378
01379 }
01380
01381 return;
01382
01383 }
01384
01385 void UberModuleLite::FillNtpTrackFidAll(NtpSRTrack* ntptrack,
01386 const CandTrackHandle* track,
01387 const VldContext& vld) {
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpFiducialAll" << endl;
01401 const Double_t cos45 = 0.70710678;
01402
01403 NtpSRFiducial& fidall = ntptrack->fidall;
01404
01405 NtpSRFiducial fidtmp;
01406 NtpSRVertex vtxtmp;
01407 fidall.dr = min(ntptrack->fidvtx.dr,ntptrack->fidend.dr);
01408 fidall.dz = min(ntptrack->fidvtx.dz,ntptrack->fidend.dz);
01409 fidall.trace = min(ntptrack->fidvtx.trace,ntptrack->fidend.trace);
01410 fidall.tracez = min(ntptrack->fidvtx.tracez,ntptrack->fidend.tracez);
01411 fidall.nplane = min(ntptrack->fidvtx.nplane,ntptrack->fidend.nplane);
01412
01413
01414
01415 TIter trackstripItr(track->GetDaughterIterator());
01416 while(CandStripHandle* trackstrip = dynamic_cast<CandStripHandle*>
01417 (trackstripItr())) {
01418
01419 Int_t iplane = trackstrip->GetPlane();
01420 vtxtmp.plane = iplane;
01421 vtxtmp.u = track->GetU(iplane);
01422 vtxtmp.v = track->GetV(iplane);
01423 vtxtmp.x = cos45*(vtxtmp.u-vtxtmp.v);
01424 vtxtmp.y = cos45*(vtxtmp.u+vtxtmp.v);
01425 this->FillNtpFiducial(fidtmp,vtxtmp,vld);
01426 fidall.dr = min(fidtmp.dr,fidall.dr);
01427 fidall.dz = min(fidtmp.dz,fidall.dz);
01428 }
01429
01430 return;
01431
01432 }
01433
01434 void UberModuleLite::FillNtpTrackVertex(NtpSRTrack* ntptrack,
01435 const CandTrackHandle* track) {
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackVertex" << endl;
01446
01447 const Double_t cos45 = 0.70710678;
01448
01449 NtpSRVertex& vtx = ntptrack->vtx;
01450
01451
01452 vtx.u = track->GetVtxU();
01453 vtx.v = track->GetVtxV();
01454 vtx.x = cos45*(vtx.u-vtx.v);
01455 vtx.y = cos45*(vtx.u+vtx.v);
01456 vtx.z = track->GetVtxZ();
01457 vtx.t = track->GetVtxT();
01458 vtx.plane = track->GetVtxPlane();
01459 vtx.dcosu = track->GetDirCosU();
01460 vtx.dcosv = track->GetDirCosV();
01461 vtx.dcosx = cos45*(vtx.dcosu-vtx.dcosv);
01462 vtx.dcosy = cos45*(vtx.dcosu+vtx.dcosv);
01463 vtx.dcosz = track->GetDirCosZ();
01464
01465 const CandFitTrackSRHandle* fittracksr
01466 = dynamic_cast<const CandFitTrackSRHandle*>(track);
01467 if ( fittracksr ) {
01468 vtx.eu = fittracksr->GetVtxUError();
01469 vtx.ev = fittracksr->GetVtxVError();
01470 vtx.ex = cos45*sqrt(vtx.eu*vtx.eu+vtx.ev*vtx.ev);
01471 vtx.ey = cos45*sqrt(vtx.eu*vtx.eu+vtx.ev*vtx.ev);
01472 Double_t edudz = fittracksr->GetVtxdUError();
01473 Double_t edvdz = fittracksr->GetVtxdVError();
01474
01475
01476 vtx.edcosz = fabs(vtx.dcosz)*sqrt(pow(vtx.dcosu*edudz,2)+
01477 pow(vtx.dcosv*edvdz,2));
01478 vtx.edcosu = sqrt(fabs(vtx.dcosz))*sqrt(pow(vtx.dcosu*vtx.dcosv*edvdz,2)
01479 + pow((pow(vtx.dcosz,2)+pow(vtx.dcosv,2))*edudz,2));
01480 vtx.edcosv = sqrt(fabs(vtx.dcosz))*sqrt(pow(vtx.dcosu*vtx.dcosv*edudz,2)
01481 + pow((pow(vtx.dcosz,2)+pow(vtx.dcosu,2))*edvdz,2));
01482 vtx.edcosx = cos45*sqrt(vtx.edcosu*vtx.edcosu+vtx.edcosv*vtx.edcosv);
01483 vtx.edcosy = cos45*sqrt(vtx.edcosu*vtx.edcosu+vtx.edcosv*vtx.edcosv);
01484 }
01485
01486 return;
01487
01488 }
01489
01490 void UberModuleLite::FillNtpTrackEnd(NtpSRTrack* ntptrack,
01491 const CandTrackHandle* track) {
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpTrackEnd" << endl;
01502
01503 const Double_t cos45 = 0.70710678;
01504
01505 NtpSRVertex& end = ntptrack->end;
01506
01507
01508 end.u = track->GetEndU();
01509 end.v = track->GetEndV();
01510 end.x = cos45*(end.u-end.v);
01511 end.y = cos45*(end.u+end.v);
01512 end.z = track->GetEndZ();
01513 end.t = track->GetEndT();
01514 end.plane = track->GetEndPlane();
01515 end.dcosu = track->GetEndDirCosU();
01516 end.dcosv = track->GetEndDirCosV();
01517 end.dcosx = cos45*(end.dcosu-end.dcosv);
01518 end.dcosy = cos45*(end.dcosu+end.dcosv);
01519 end.dcosz = track->GetEndDirCosZ();
01520
01521 const CandFitTrackSRHandle* fittracksr
01522 =dynamic_cast<const CandFitTrackSRHandle*>(track);
01523 if ( fittracksr ) {
01524 end.eu = fittracksr->GetEndUError();
01525 end.ev = fittracksr->GetEndVError();
01526 end.ex = cos45*sqrt(end.eu*end.eu+end.ev*end.ev);
01527 end.ey = cos45*sqrt(end.eu*end.eu+end.ev*end.ev);
01528 Double_t edudz = fittracksr->GetEnddUError();
01529 Double_t edvdz = fittracksr->GetEnddVError();
01530
01531
01532 end.edcosz = fabs(end.dcosz)*sqrt(pow(end.dcosu*edudz,2)+
01533 pow(end.dcosv*edvdz,2));
01534 end.edcosu = sqrt(fabs(end.dcosz))*sqrt(pow(end.dcosu*end.dcosv*edvdz,2)
01535 + pow((pow(end.dcosz,2)+pow(end.dcosv,2))*edudz,2));
01536 end.edcosv = sqrt(fabs(end.dcosz))*sqrt(pow(end.dcosu*end.dcosv*edudz,2)
01537 + pow((pow(end.dcosz,2)+pow(end.dcosu,2))*edvdz,2));
01538 end.edcosx = cos45*sqrt(end.edcosu*end.edcosu+end.edcosv*end.edcosv);
01539 end.edcosy = cos45*sqrt(end.edcosu*end.edcosu+end.edcosv*end.edcosv);
01540 }
01541
01542 return;
01543
01544 }
01545
01546 void UberModuleLite::FillNtpTrackLinearFit(NtpSRTrack* ntptrack,
01547 const CandTrackHandle* track) {
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpFitTrack" << endl;
01559
01560 const Double_t cos45 = 0.70710678;
01561
01562
01563
01564 const Int_t nplane = 1000;
01565 const Int_t nview = 2;
01566 Double_t zfit[nview][nplane]={{0},{0}},fit[nview][nplane]={{0},{0}};
01567 Double_t wfit[nview][nplane]={{0},{0}},ph[nview][nplane]={{0},{0}};
01568
01569
01570 TIter trackstripItr(track->GetDaughterIterator());
01571 while(CandStripHandle* trackstrip = dynamic_cast<CandStripHandle*>
01572 (trackstripItr())) {
01573
01574 Float_t tpos = trackstrip->GetTPos();
01575 Float_t phend[2] = {trackstrip->GetCharge(StripEnd::kNegative),
01576 trackstrip->GetCharge(StripEnd::kPositive)};
01577 Float_t phsum = phend[0] + phend[1];
01578
01579 Int_t iplane = trackstrip->GetPlane();
01580 assert(iplane >= 0 && iplane < 1000);
01581
01582 Int_t iview = -1;
01583 if ( trackstrip->GetPlaneView()==PlaneView::kU ) iview = 0;
01584 else if ( trackstrip->GetPlaneView()==PlaneView::kV ) iview = 1;
01585 else continue;
01586
01587 zfit[iview][iplane] = trackstrip->GetZPos();
01588 fit[iview][iplane] += tpos*phsum;
01589 ph[iview][iplane] += phsum;
01590 wfit[iview][iplane] = 1;
01591 }
01592
01593
01594 for ( Int_t ip = 0; ip < nplane; ip++ ) {
01595 for ( Int_t iv = 0; iv < nview; iv++ ) {
01596 if ( ph[iv][ip] > 0 ) fit[iv][ip] /= ph[iv][ip];
01597 }
01598 }
01599
01600 Double_t uparm[2],ueparm[2],vparm[2],veparm[2];
01601 LinearFit::Weighted(1000,zfit[0],fit[0],wfit[0],uparm,ueparm);
01602 LinearFit::Weighted(1000,zfit[1],fit[1],wfit[1],vparm,veparm);
01603 NtpSRVertex& lin = ntptrack->lin;
01604
01605 Double_t dudz = uparm[1];
01606 Double_t dvdz = vparm[1];
01607 Double_t dxdz = cos45*(uparm[1]-vparm[1]);
01608 Double_t dydz = cos45*(uparm[1]+vparm[1]);
01609 lin.z = track->GetVtxZ();
01610 lin.t = track->GetVtxT();
01611 lin.u = uparm[0]+lin.z*dudz;
01612 lin.v = vparm[0]+lin.z*dvdz;
01613 lin.x = cos45*(uparm[0]-vparm[0])+lin.z*dxdz;
01614 lin.y = cos45*(uparm[0]+vparm[0])+lin.z*dydz;
01615 Double_t anorm = sqrt(1.+dxdz*dxdz+dydz*dydz);
01616 Int_t sign = 1;
01617 if ( track->GetTimeSlope() < 0. ) sign = -1;
01618 lin.dcosu = sign*dudz/anorm;
01619 lin.dcosv = sign*dvdz/anorm;
01620 lin.dcosx = sign*dxdz/anorm;
01621 lin.dcosy = sign*dydz/anorm;
01622 lin.dcosz = sign*1./anorm;
01623
01624 return;
01625
01626 }
01627
01628
01629
01630
01631
01632 void UberModuleLite::FillNtpFiducial(NtpSRFiducial& fid, const NtpSRVertex& vtx,
01633 const VldContext& vld) {
01634
01635
01636
01637
01638
01639
01640
01641
01642 MSG("UberModuleLite",Msg::kVerbose) << "UberModuleLite::FillNtpFiducial" << endl;
01643
01644 UgliGeomHandle ugh(vld);
01645 Float_t zextent[2];
01646 ugh.GetZExtent(zextent[0],zextent[1]);
01647 Detector::Detector_t dtype = vld.GetDetector();
01648
01649 Float_t du,dv,dx,dy;
01650
01651 switch (dtype) {
01652
01653 case Detector::kFar:
01654 du = min(4.-vtx.u,4.+vtx.u);
01655 dv = min(4.-vtx.v,4.+vtx.v);
01656 dx = min(4.-vtx.x,4.+vtx.x);
01657 dy = min(4.-vtx.y,4.+vtx.y);
01658 fid.dr = min(min(du,dv),min(dx,dy));
01659 if ( fid.dr < 0. ) fid.dr = 0;
01660 fid.dz = min(vtx.z-zextent[0],zextent[1]-vtx.z);
01661
01662 break;
01663
01664 case Detector::kCalDet:
01665 fid.dr = min(min(0.5+vtx.x,0.5-vtx.x),min(0.5+vtx.y,0.5-vtx.y));
01666 if ( fid.dr < 0. ) fid.dr = 0;
01667 fid.dz = min(vtx.z-zextent[0],zextent[1]-vtx.z);
01668
01669 break;
01670
01671 default:
01672 MSG("EventSR",Msg::kWarning) << "Detector type " << dtype
01673 << " not supported." << endl;
01674 break;
01675 }
01676
01677 return;
01678
01679 }