00001
00002
00003
00004 #include "TClonesArray.h"
00005
00006
00007 #include "CandNtupleSR/NtpSREvent.h"
00008 #include "CandNtupleSR/NtpSRShower.h"
00009 #include "CandNtupleSR/NtpSRSlice.h"
00010 #include "CandNtupleSR/NtpSRStrip.h"
00011 #include "CandNtupleSR/NtpSRTrack.h"
00012 #include "MessageService/MsgService.h"
00013 #include "MinosObjectMap/MomNavigator.h"
00014 #include "Plex/PlexStripEndId.h"
00015 #include "StandardNtuple/NtpStRecord.h"
00016 #include "Validity/VldContext.h"
00017
00018
00019 #include "PhysicsNtuple/Default.h"
00020 #include "PhysicsNtuple/Factory.h"
00021
00022
00023 #include "FillStrip.h"
00024
00025 CVSID("$Id: FillStrip.cxx,v 1.17 2008/01/31 22:18:17 rustem Exp $");
00026
00027 REGISTER_ANP_OBJECT(AlgStore,FillStrip)
00028
00029 using namespace std;
00030
00031
00032 Anp::FillStrip::FillStrip()
00033 {
00034 }
00035
00036
00037 Anp::FillStrip::~FillStrip()
00038 {
00039 }
00040
00041
00042 bool Anp::FillStrip::Run(Record &record, TObject *ptr)
00043 {
00044
00045
00046
00047
00048 NtpStRecord *ntprec = dynamic_cast<NtpStRecord *>(ptr);
00049 if(!ntprec)
00050 {
00051 const MomNavigator *mom = dynamic_cast<const MomNavigator *> (ptr);
00052 if(mom)
00053 {
00054 ntprec = dynamic_cast<NtpStRecord *>(mom -> GetFragment("NtpStRecord"));
00055 }
00056 else
00057 {
00058 MSG("FillAlg", Msg::kError) << "Failed to find MomNavigator pointer" << endl;
00059 return false;
00060 }
00061 }
00062
00063 if(!ntprec)
00064 {
00065 MSG("FillAlg", Msg::kError) << "Failed to get NtpStRecord pointer" << endl;
00066 return false;
00067 }
00068
00069 const TClonesArray *strip_array = ntprec -> stp;
00070 if(!strip_array)
00071 {
00072 MSG("FillAlg", Msg::kWarning) << "NtpStRecord does not have valid strip array." << endl;
00073 return false;
00074 }
00075
00076 const int nstrip = strip_array -> GetEntries();
00077 if(nstrip != strip_array -> GetEntriesFast())
00078 {
00079 MSG("FillAlg", Msg::kWarning) << "NtpSRStrip TClonesArray.has holes" << endl;
00080 }
00081
00082 std::vector<Anp::Strip> &strip_vec = record.GetStrip();
00083
00084
00085 strip_vec.clear();
00086 strip_vec.insert(strip_vec.begin(), nstrip, Anp::Strip());
00087
00088 const Detector::Detector_t detector = ntprec -> GetHeader().GetVldContext().GetDetector();
00089
00090 for(int i_strip = 0; i_strip != nstrip; ++i_strip)
00091 {
00092 const NtpSRStrip *ntp_strip = dynamic_cast<const NtpSRStrip *>(strip_array -> At(i_strip));
00093 if(!ntp_strip)
00094 {
00095 MSG("FillAlg", Msg::kWarning) << "Could not get NtpSRStrip" << endl;
00096 continue;
00097 }
00098 if(i_strip != ntp_strip -> index)
00099 {
00100 MSG("FillAlg", Msg::kWarning) << "Wrong strip and TClonesArray index" << endl;
00101 continue;
00102 }
00103
00104 Anp::Strip &strip = strip_vec[i_strip];
00105
00106 strip.index = ntp_strip -> index;
00107 strip.strip = ntp_strip -> strip;
00108 strip.plane = ntp_strip -> plane;
00109 strip.ndigit = ntp_strip -> ndigit;
00110 strip.planeview = ntp_strip -> planeview;
00111 strip.tpos = ntp_strip -> tpos;
00112 strip.zpos = ntp_strip -> z;
00113
00114 if(detector == Detector::kNear)
00115 {
00116 if(ntp_strip -> pmtindex0 > 0)
00117 {
00118 MSG("FillAlg", Msg::kWarning) << "Near detector has east strip readout " << endl;
00119 continue;
00120 }
00121 if(ntp_strip -> pmtindex1 < 0 || !(ntp_strip -> ph1.raw > 0.0))
00122 {
00123 MSG("FillAlg", Msg::kWarning) << "Near detector does not have west strip readout " << endl;
00124 continue;
00125 }
00126
00127 strip.adc = ntp_strip -> ph1.raw;
00128 strip.pe = ntp_strip -> ph1.pe;
00129 strip.siglin = ntp_strip -> ph1.siglin;
00130 strip.sigcor0 = 0.0;
00131 strip.sigcor1 = ntp_strip -> ph1.sigcor;
00132 strip.time0 = 0.0;
00133 strip.time1 = ntp_strip -> time1;
00134 strip.pmtindex0 = -1;
00135 strip.pmtindex1 = ntp_strip -> pmtindex1;
00136 }
00137 else if(detector == Detector::kFar)
00138 {
00139 if(!(ntp_strip -> pmtindex0 >= 0) && !(ntp_strip -> pmtindex1 >= 0))
00140 {
00141 MSG("FillAlg", Msg::kWarning) << "Far detector does not have valid strip readout " << endl
00142 << *ntp_strip;
00143 continue;
00144 }
00145
00146 if(!(ntp_strip -> ph0.raw > 0.0) && !(ntp_strip -> ph1.raw > 0.0))
00147 {
00148 MSG("FillAlg", Msg::kWarning) << "Far detector does not have valid strip readout " << endl
00149 << *ntp_strip;
00150 continue;
00151 }
00152
00153 strip.adc = 0.0;
00154 strip.pe = 0.0;
00155 strip.siglin = 0.0;
00156 strip.sigcor0 = 0.0;
00157 strip.sigcor1 = 0.0;
00158
00159 if(ntp_strip -> pmtindex0 > 0 ||
00160 (ntp_strip -> pmtindex0 == 0 && ntp_strip -> ph0.raw > 0.0))
00161 {
00162 strip.adc += ntp_strip -> ph0.raw;
00163 strip.pe += ntp_strip -> ph0.pe;
00164 strip.siglin += ntp_strip -> ph0.siglin;
00165
00166 strip.sigcor0 = ntp_strip -> ph0.sigcor;
00167 strip.time0 = ntp_strip -> time0;
00168 strip.pmtindex0 = ntp_strip -> pmtindex0;
00169 }
00170
00171 if(ntp_strip -> pmtindex1 > 0 ||
00172 (ntp_strip -> pmtindex1 == 0 && ntp_strip -> ph1.raw > 0.0))
00173 {
00174 strip.adc += ntp_strip -> ph1.raw;
00175 strip.pe += ntp_strip -> ph1.pe;
00176 strip.siglin += ntp_strip -> ph1.siglin;
00177
00178 strip.sigcor1 = ntp_strip -> ph1.sigcor;
00179 strip.time1 = ntp_strip -> time1;
00180 strip.pmtindex1 = ntp_strip -> pmtindex1;
00181 }
00182 }
00183 else
00184 {
00185 MSG("FillAlg", Msg::kWarning) << "Unknown detector type" << endl;
00186 }
00187
00188 const PlexStripEndId seid = GetSEID(strip, detector);
00189
00190 if(seid.GetPlane() != strip.plane || seid.GetStrip() != strip.strip)
00191 {
00192 MSG("FillAlg", Msg::kError) << "Mismatch between Plex and Strip" << endl;
00193 }
00194
00195 strip.seid = seid.GetEncoded();
00196 }
00197
00198 GetEvtStrip(strip_vec, *ntprec);
00199 GetShwStrip(strip_vec, *ntprec);
00200 GetSlcStrip(strip_vec, *ntprec);
00201 GetTrkStrip(strip_vec, *ntprec);
00202
00203 return true;
00204 }
00205
00206
00207 void Anp::FillStrip::Config(const Registry &)
00208 {
00209
00210
00211
00212 }
00213
00214
00215 void Anp::FillStrip::GetEvtStrip(SVec &svec, const NtpStRecord &ntprec) const
00216 {
00217 const TClonesArray *event_array = ntprec.evt;
00218 if(!event_array)
00219 {
00220 MSG("FillAlg", Msg::kWarning) << "NtpStRecord does not have valid event array" << endl;
00221 return;
00222 }
00223
00224 const short size = svec.size();
00225 const int nevent = event_array -> GetEntries();
00226
00227 for(int i_event = 0; i_event != nevent; ++i_event)
00228 {
00229 const NtpSREvent* ntpevt = dynamic_cast<const NtpSREvent *> (event_array -> At(i_event));
00230 if(!ntpevt)
00231 {
00232 MSG("FillAlg", Msg::kWarning) << "Failed to find NtpSREvent at "<< i_event << endl;
00233 continue;
00234 }
00235
00236 const short index = ntpevt -> index;
00237 if(index != i_event)
00238 {
00239 MSG("FillAlg", Msg::kError) << "NtpSREvent "<< index << " has mistmatched index" << endl;
00240 continue;
00241 }
00242
00243 if(!ntpevt -> stp)
00244 {
00245 MSG("FillAlg", Msg::kWarning) << "NtpSREvent "<< index << " doesn't have strip array" << endl;
00246 continue;
00247 }
00248
00249 for(short i_strip = 0; i_strip < ntpevt -> nstrip; ++i_strip)
00250 {
00251 const short strip_index = ntpevt -> stp[i_strip];
00252
00253 if(strip_index < 0 || strip_index >= size)
00254 {
00255 MSG("FillAlg", Msg::kWarning) << "Strip index is out of range: " << strip_index << endl;
00256 continue;
00257 }
00258
00259 Strip &strip = svec[strip_index];
00260 if(strip.index < 0 || strip.index != strip_index)
00261 {
00262 MSG("FillAlg", Msg::kWarning) << "Mismateched strip index" << endl;
00263 }
00264 else
00265 {
00266 strip.evt.push_back(index);
00267 }
00268 }
00269 }
00270 }
00271
00272
00273 void Anp::FillStrip::GetSlcStrip(SVec &svec, const NtpStRecord &ntprec) const
00274 {
00275 const TClonesArray *slice_array = ntprec.slc;
00276 if(!slice_array)
00277 {
00278 MSG("FillAlg", Msg::kWarning) << "NtpStRecord does not have valid slice array." << endl;
00279 return;
00280 }
00281
00282 const short size = svec.size();
00283 const int nslice = slice_array -> GetEntries();
00284
00285 for(int i_slice = 0; i_slice != nslice; ++i_slice)
00286 {
00287 const NtpSRSlice* ntp_slice = dynamic_cast<const NtpSRSlice *> (slice_array -> At(i_slice));
00288 if(!ntp_slice)
00289 {
00290 MSG("FillAlg", Msg::kWarning) << "Failed to find NtpSRSlice at "<< i_slice << endl;
00291 continue;
00292 }
00293
00294 const short index = ntp_slice -> index;
00295 if(index != i_slice)
00296 {
00297 MSG("FillAlg", Msg::kError) << "NtpSRSlice "<< index << " has mistmatched index" << endl;
00298 continue;
00299 }
00300
00301 if(!ntp_slice -> stp)
00302 {
00303 MSG("FillAlg", Msg::kWarning) << "NtpSRSlice "<< index << " doesn't have strip array" << endl;
00304 continue;
00305 }
00306
00307 for(short i_strip = 0; i_strip < ntp_slice -> nstrip; ++i_strip)
00308 {
00309 const short strip_index = ntp_slice -> stp[i_strip];
00310
00311 if(strip_index < 0 || strip_index >= size)
00312 {
00313 MSG("FillAlg", Msg::kWarning) << "Strip index is out of range: " << strip_index << endl;
00314 continue;
00315 }
00316
00317 Strip &strip = svec[strip_index];
00318 if(strip.index < 0 || strip.index != strip_index)
00319 {
00320 MSG("FillAlg", Msg::kWarning) << "Mismateched strip index" << endl;
00321 }
00322 else
00323 {
00324 strip.slc.push_back(index);
00325 }
00326 }
00327 }
00328 }
00329
00330
00331 void Anp::FillStrip::GetShwStrip(SVec &svec, const NtpStRecord &ntprec) const
00332 {
00333 const TClonesArray *shower_array = ntprec.shw;
00334 if(!shower_array)
00335 {
00336 MSG("FillAlg", Msg::kWarning) << "NtpStRecord does not have valid shower array." << endl;
00337 return;
00338 }
00339
00340 const short size = svec.size();
00341 const int nshower = shower_array -> GetEntries();
00342
00343 for(int i_shower = 0; i_shower != nshower; ++i_shower)
00344 {
00345 const NtpSRShower* ntpshw = dynamic_cast<const NtpSRShower *> (shower_array -> At(i_shower));
00346 if(!ntpshw)
00347 {
00348 MSG("FillAlg", Msg::kWarning) << "Failed to find NtpSRShower at "<< i_shower << endl;
00349 continue;
00350 }
00351
00352 const short index = ntpshw -> index;
00353 if(index != i_shower)
00354 {
00355 MSG("FillAlg", Msg::kError) << "NtpSRShower "<< index << " has mistmatched index" << endl;
00356 continue;
00357 }
00358
00359 if(!ntpshw -> stp)
00360 {
00361 MSG("FillAlg", Msg::kWarning) << "NtpSRShower "<< index << " doesn't have strip array" << endl;
00362 continue;
00363 }
00364
00365 for(short i_strip = 0; i_strip < ntpshw -> nstrip; ++i_strip)
00366 {
00367 const short strip_index = ntpshw -> stp[i_strip];
00368
00369 if(strip_index < 0 || strip_index >= size)
00370 {
00371 MSG("FillAlg", Msg::kWarning) << "Strip index is out of range: " << strip_index << endl;
00372 continue;
00373 }
00374
00375 Strip &strip = svec[strip_index];
00376 if(strip.index < 0 || strip.index != strip_index)
00377 {
00378 MSG("FillAlg", Msg::kWarning) << "Mismateched strip index" << endl;
00379 }
00380 else
00381 {
00382 strip.shw.push_back(index);
00383 }
00384 }
00385 }
00386 }
00387
00388
00389 void Anp::FillStrip::GetTrkStrip(SVec &svec, const NtpStRecord &ntprec) const
00390 {
00391 const TClonesArray *track_array = ntprec.trk;
00392 if(!track_array)
00393 {
00394 MSG("FillAlg", Msg::kWarning) << "NtpStRecord does not have valid track array." << endl;
00395 return;
00396 }
00397
00398 const short size = svec.size();
00399 const int ntrack = track_array -> GetEntries();
00400
00401 for(int i_track = 0; i_track != ntrack; ++i_track)
00402 {
00403 const NtpSRTrack* ntptrk = dynamic_cast<const NtpSRTrack *> (track_array -> At(i_track));
00404 if(!ntptrk)
00405 {
00406 MSG("FillAlg", Msg::kWarning) << "Failed to find NtpSRTrack at "<< i_track << endl;
00407 continue;
00408 }
00409
00410 const short index = ntptrk -> index;
00411 if(index != i_track)
00412 {
00413 MSG("FillAlg", Msg::kError) << "NtpSRTrack "<< index << " has mistmatched index" << endl;
00414 continue;
00415 }
00416
00417 if(!ntptrk -> stp)
00418 {
00419 MSG("FillAlg", Msg::kWarning) << "NtpSRTrack "<< index << " doesn't have strip array" << endl;
00420 continue;
00421 }
00422
00423 for(short i_strip = 0; i_strip < ntptrk -> nstrip; ++i_strip)
00424 {
00425 const short strip_index = ntptrk -> stp[i_strip];
00426
00427 if(strip_index < 0 || strip_index >= size)
00428 {
00429 MSG("FillAlg", Msg::kWarning) << "Strip index is out of range: " << strip_index << endl;
00430 continue;
00431 }
00432
00433 Strip &strip = svec[strip_index];
00434 if(strip.index < 0 || strip.index != strip_index)
00435 {
00436 MSG("FillAlg", Msg::kError) << "Mismateched strip index" << endl;
00437 continue;
00438 }
00439
00440 strip.trk.push_back(index);
00441
00442 Strip::TrackInfo info;
00443
00444 info.vpos = ntptrk -> stpv[i_strip];
00445 info.upos = ntptrk -> stpu[i_strip];
00446
00447 info.sigmap_east = ntptrk -> stpph0sigmap[i_strip];
00448 info.sigmap_west = ntptrk -> stpph1sigmap[i_strip];
00449 info.mip_east = ntptrk -> stpph0mip[i_strip];
00450 info.mip_west = ntptrk -> stpph1mip[i_strip];
00451
00452 if(!strip.trk_info.insert(Strip::TrackInfoMap::value_type(index, info)).second)
00453 {
00454 MSG("FillAlg", Msg::kWarning) << "Failed to insert TrackInfo structure" << endl;
00455 }
00456 }
00457 }
00458 }
00459
00460
00461 const PlexStripEndId Anp::FillStrip::GetSEID(const Strip &strip, const Detector::Detector_t det) const
00462 {
00463 StripEnd::StripEnd_t end = StripEnd::kWest;
00464 if(det == Detector::kFar)
00465 {
00466 if((strip.pmtindex0 >= 0 && strip.sigcor0 > 0.0) &&
00467 (strip.pmtindex1 >= 0 && strip.sigcor1 > 0.0))
00468 {
00469 end = StripEnd::kWhole;
00470 }
00471 else if(strip.pmtindex0 >= 0 && strip.sigcor0 > 0.0)
00472 {
00473 end = StripEnd::kEast;
00474 }
00475 else if(strip.pmtindex1 >= 0 && strip.sigcor1 > 0.0)
00476 {
00477 end = StripEnd::kWest;
00478 }
00479 else
00480 {
00481 cerr << "FillStrip::GetSEID - failed to determine strip end" << endl;
00482 }
00483 }
00484
00485 return PlexStripEndId(det, strip.plane, strip.strip, end);
00486 }