Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PlexusReroot.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PlexusReroot.cxx,v 1.15 2006/12/03 01:52:59 gmieg Exp $
00003 //
00004 // PlexusReroot
00005 //
00006 // PlexusReroot is an actual connection map
00007 //   that derives its information from the connected REROOT file
00008 //
00009 // Author:  R. Hatcher 2000.05.03
00010 //
00012 
00013 #include "RerootExodus/PlexusReroot.h"
00014 #include "Validity/VldContext.h"
00015 
00016 #include "MessageService/MsgService.h"
00017 CVSID("$Id: PlexusReroot.cxx,v 1.15 2006/12/03 01:52:59 gmieg Exp $");
00018 
00019 #include <iomanip>
00020 
00021 #include "RerootExodus/RerootExodus.h"
00022 
00023 ClassImp(PlexusReroot)
00024 
00025 //_____________________________________________________________________________
00026 PlexusReroot::PlexusReroot()
00027    : Plexus(), fNStrips(0), fStripToPixelModulo(0), fStripToPixelPermute(0)
00028 {
00029    // Default constructor
00030 
00031    MSG("Plex",Msg::kVerbose) << "default ctor" << endl;
00032 
00033    fVldRange = RerootExodus::BuildVldRange();
00034 }
00035 
00036 //_____________________________________________________________________________
00037 PlexusReroot::PlexusReroot(const VldContext& /* vldc */)
00038    : Plexus(), fNStrips(0), fStripToPixelModulo(0), fStripToPixelPermute(0)
00039 {
00040    // normal constructor
00041 
00042    MSG("Plex",Msg::kInfo) << " PlexusReroot vldc ctor " << endl;
00043 
00044    fVldRange = RerootExodus::BuildVldRange();
00045 }
00046 
00047 //_____________________________________________________________________________
00048 PlexusReroot::~PlexusReroot()
00049 {
00050    // delete all the owned sub-objects
00051 
00052    delete [] fStripToPixelModulo;
00053    delete [] fStripToPixelPermute;
00054 
00055 }
00056 
00057 //_____________________________________________________________________________
00058 RawChannelId PlexusReroot::GetRawChannelId(const PlexStripEndId& pseid) const
00059 {
00060    // Convert PlexStripEndId into RawChannelId (m:1 mapping)
00061 
00062    // Choose a particular mapping
00063    // Assume that the "modulo" side is always on the West
00064    // and the permute side is on the East
00065    // (this keeps one-sided near spectrometer as "modulo")
00066 
00067    BuildPermute(pseid.GetPlane());
00068 
00069    ElecType::Elec_t elec = ElecType::kReroot;
00070    Int_t crate = -1;
00071    Int_t chadd = -1;
00072 
00073    Int_t plane = pseid.GetPlane();
00074    Int_t strip = pseid.GetStrip();
00075    StripEnd::StripEnd_t end = pseid.GetEnd();
00076    Int_t pixel;
00077 
00078    // map strip to pixel depending on the side
00079    switch (end) {
00080    case StripEnd::kEast:
00081       pixel = fStripToPixelPermute[strip];
00082       break;
00083    case StripEnd::kWest:
00084       pixel = fStripToPixelModulo[strip];
00085       break;
00086    default:
00087       pixel = -1;
00088       // dump out message
00089       MSG("Plex",Msg::kFatal) 
00090          << "PlexusExodus::GetRawChannelId(seid) illegal side " 
00091          << StripEnd::AsString(pseid.GetEnd()) << endl;
00092    }
00093 
00094    // special cases
00095 
00096    Detector::Detector_t detector = pseid.GetDetector();
00097 
00098    // near detector calorimeter has no MUX
00099    if (Detector::kNear == detector) {
00100       if ( pseid.GetPlane() <= 120 ) {
00101          pixel = strip;
00102       }
00103    }
00104 
00105    // calibration detector (CalDet) has no MUX
00106    if (Detector::kCalDet == detector) {
00107       pixel = strip;
00108    }
00109 
00110    // illegal strip
00111    if ( strip >= fNStrips ) {
00112       pixel = -1;
00113       // dump out message
00114       MSG("Plex",Msg::kFatal) 
00115          << "PlexusExodus::GetRawChannelId(seid) illegal strip # "
00116          << pseid.AsString() << " in " << fActvNameStrip2Pixel 
00117          << " which has " << fNStrips << " strips " << endl;
00118    }
00119 
00120    MangleFakeCrate(plane,pixel,end,crate,chadd);
00121    
00122    return RawChannelId(detector,elec,crate,chadd);
00123    
00124 }
00125 
00126 //_____________________________________________________________________________
00127 RawChannelId PlexusReroot::GetRawChannelId(const PlexPixelSpotId& psid) const
00128 {
00129    // Convert PlexPixelSpotId into a RawChannelId
00130    // not supported under Reroot
00131    MSG("Exodus",Msg::kError)
00132      << "GetRawChannelId(PlexPixelSpotId) not supported: "
00133      << psid << endl;
00134    return RawChannelId();
00135 }
00136 
00137 //_____________________________________________________________________________
00138 RawChannelId PlexusReroot::GetRawChannelId(const PlexPinDiodeId& diodeid) const
00139 {
00140    // Convert PlexPinDiodeId into a RawChannelId
00141    // not supported under Reroot
00142    MSG("Exodus",Msg::kError)
00143      << "GetRawChannelId(PlexPinDiodeId) not supported: "
00144      << diodeid << endl;
00145    return RawChannelId();
00146 }
00147 
00148 //_____________________________________________________________________________
00149 PlexPinDiodeId PlexusReroot::GetPinDiodeId(const RawChannelId& rcid) const
00150 {
00151    // Convert RawChannelId into PlexPinDiodeId (if possible)
00152    // not supported under Reroot
00153    MSG("Exodus",Msg::kError)
00154      << "GetPinDiodeId(RawChannelId) not supported: "
00155      << rcid << endl;
00156    return PlexPinDiodeId();
00157 }
00158 
00159 //_____________________________________________________________________________
00160 PlexSEIdAltL PlexusReroot::GetSEIdAltL(const RawChannelId& rcid,
00161                                        const PlexCalib* calib,
00162                                        Int_t adc, Double_t time) const
00163 {
00164    // Convert RawChannelId into PlexStripEndId Alternative List (1:m mapping)
00165 
00166    Int_t plane = -1;
00167    StripEnd::StripEnd_t end = StripEnd::kUnknown;
00168    Int_t pixel = -1;
00169 
00170    DemangleFakeCrate(rcid.GetCrate(),rcid.GetChAdd(),plane,pixel,end);
00171 
00172    // build a base SEId that has view&coverage correctly set
00173    // but just setting plane # (detector determined from Reroot event)
00174    Int_t rpln = RerootExodus::SteelToRerootPlane(plane,kTRUE);
00175    PlexStripEndId pseid_base = RerootExodus::PECAB2SEId(rpln,0,0,0);
00176    Detector::Detector_t detector = pseid_base.GetDetector();
00177 
00178    // Build the permutation lists
00179    BuildPermute(plane);
00180 
00181    PlexSEIdAltL   altlist;
00182    
00183    // special cases
00184 
00185    // near detector calorimeter has no MUX
00186    if ( Detector::kNear == detector && plane < 121 ) {
00187       Int_t strip = pixel;
00188       pseid_base.SetStrip(strip);
00189       pseid_base.SetEnd(end);
00190       PlexPixelSpotId spotid;
00191       altlist.AddStripEndId(pseid_base,spotid,0,calib,adc,time);
00192       return altlist;
00193    }
00194 
00195    // calibration detector (CalDet) has no MUX
00196    if ( Detector::kCalDet == detector ) {
00197       Int_t strip = pixel;
00198       pseid_base.SetStrip(strip);
00199       pseid_base.SetEnd(end);
00200       PlexPixelSpotId spotid;
00201       altlist.AddStripEndId(pseid_base,spotid,0,calib,adc,time);
00202       return altlist;
00203    }
00204 
00205    for (Int_t strip = 0; strip < fNStrips; strip++) {
00206       Bool_t test = kFALSE;
00207       switch ( end ) {
00208       case StripEnd::kWest:  
00209          if ( pixel == fStripToPixelModulo[strip] )  test = kTRUE;
00210          break;
00211       case StripEnd::kEast:
00212          if ( pixel == fStripToPixelPermute[strip] ) test = kTRUE;
00213          break;
00214       default:
00215          break;
00216       }
00217       if (test) {
00218          pseid_base.SetStrip(strip);
00219          pseid_base.SetEnd(end);
00220          PlexPixelSpotId spotid;
00221          altlist.AddStripEndId(pseid_base,spotid,0,calib,adc,time);
00222       }
00223    }
00224 
00225    return altlist;
00226 
00227 
00228 }
00229 
00230 //_____________________________________________________________________________
00231 ReadoutType::Readout_t PlexusReroot::GetReadoutType(const RawChannelId& rcid) const
00232 { 
00233    // Determine what (eg. scint strip, pin diode, cerenkov, tof) 
00234    // is attached to raw channel
00235 
00236    MSG("Exodus",Msg::kVerbose)
00237      << "GetReadoutType(RawChannelId) always returns kScintStrip " 
00238      << rcid
00239      << endl;
00240    return ReadoutType::kScintStrip;  // for now there isn't anything but
00241 }
00242 
00243 //_____________________________________________________________________________
00244 void PlexusReroot::BuildPermute(const Int_t steelpln) const
00245 {
00246    // Build the permutation scheme for a given plane
00247 
00248    Int_t rpln = RerootExodus::SteelToRerootPlane(steelpln);
00249    TString reqtype = RerootExodus::ActvPlaneName(rpln);
00250 
00251    // if this map is already there simply return
00252    if (reqtype == fActvNameStrip2Pixel) return;
00253 
00254    // clear what exists
00255    delete [] fStripToPixelModulo;
00256    delete [] fStripToPixelPermute;
00257 
00258    // build the map
00259    fActvNameStrip2Pixel = reqtype;
00260    fNStrips = RerootExodus::NStripsNonZero(rpln);
00261    
00262    fStripToPixelModulo  = new Int_t [fNStrips];
00263    fStripToPixelPermute = new Int_t [fNStrips];
00264 
00265    // far detector has 192 strips, near has 64 or 96 strips per plane
00266 
00267    Int_t nstrip_swath = 1;
00268    Detector::Detector_t detector = RerootExodus::GetDetector();
00269    switch (detector) {
00270    case Detector::kNear:  nstrip_swath = 24; break;
00271    case Detector::kFar:   nstrip_swath = 24; break;
00272    default: nstrip_swath = 1;
00273    }
00274       
00275    Int_t ioff1 = 1;
00276    for (Int_t strip = 0; strip < fNStrips; strip++) {
00277       Int_t swath   = strip/nstrip_swath;
00278       Int_t inswath = strip%nstrip_swath;
00279       Int_t ioff    = swath*ioff1;
00280       Int_t permute = (strip+ioff)%nstrip_swath;
00281 
00282       fStripToPixelModulo[strip]  = inswath;
00283       fStripToPixelPermute[strip] = permute;
00284       
00285       //      MSG("Plex",Msg::kInfo) << 
00286       //         " strip "   << setw(3) << strip   <<
00287       //         " modulo "  << setw(3) << inswath << 
00288       //         " permute " << setw(3) << permute << endl;
00289 
00290       //      MSG("Plex",Msg::kInfo) << 
00291       //         " strip "   << strip   <<
00292       //         " modulo "  << inswath << 
00293       //         " permute " << permute << endl;
00294    }
00295 
00296 }
00297 
00298 //_____________________________________________________________________________
00299 void PlexusReroot::MangleFakeCrate(const Int_t plane, const Int_t pixel,
00300                                    const StripEnd::StripEnd_t end, 
00301                                    Int_t &crate, Int_t &chadd)
00302 {
00303    // chadd can only be 13 bits for raw block packing
00304    // crate can only be  6 bits for RawChannelId
00305 
00306    // mangle the bits (plane#,end#,pixel#) around some more 
00307    // to form (crate,chadd)
00308    // allow 10 bits for plane #  0:1023
00309    //        1 bits for end #    0:1  (map 1->1, 2->0)
00310    //        8 bits for pixel #  0:255
00311    // then take apart into (crate,chadd) of (8,13) bits
00312 
00313    // avoid bit 4 as this gets eaten by QIE electronics
00314 
00315    const Int_t mask13 = 0x1fff;
00316    const Int_t mask10 = 0x03ff;
00317    //const Int_t mask2  = 0x0003;
00318    const Int_t mask1  = 0x0001;
00319    const Int_t mask8  = 0x00ff;
00320    const Int_t mask6  = 0x003f;
00321    
00322    Int_t bits = ((plane    & mask10) <<  9) |
00323                 ((end      & mask1)  <<  8) | 
00324                  (pixel    & mask8);
00325 
00326    // create a hole for bit 4
00327    const Int_t low4   = 0x0000f;
00328    const Int_t high16 = 0xffff0;
00329    Int_t bitstmp = ((bits & high16) << 1) | ( bits & low4 );
00330    //cout << " create hole: 0x" << hex << bits << " -> 0x" << bitstmp << dec 
00331    //     << ((bitstmp>0x7ffff)?" too big":" ") 
00332    //     << (((bitstmp>>13)>mask6)?" crate overflow":" ")
00333    //     << endl ;
00334    bits = bitstmp;
00335 
00336    crate =    (bits >> 13) & mask6;
00337    chadd =     bits        & mask13;
00338 
00339 }
00340 void PlexusReroot::DemangleFakeCrate(const Int_t crate, Int_t chadd,
00341                                      Int_t &plane, Int_t &pixel,
00342                                      StripEnd::StripEnd_t &end)
00343 {
00344 
00345    const Int_t mask13 = 0x1fff;
00346    const Int_t mask10 = 0x03ff;
00347    //const Int_t mask2  = 0x0003;
00348    const Int_t mask1  = 0x0001;
00349    const Int_t mask8  = 0x00ff;
00350    const Int_t mask6  = 0x003f;
00351 
00352    Int_t bits = ((crate & mask6) << 13 ) | (chadd & mask13);
00353 
00354    // remove hole from bit 4
00355    const Int_t low4   = 0x0000f;
00356    const Int_t high16 = 0xffff0 << 1;
00357    Int_t bitstmp = ((bits & high16) >> 1) | ( bits & low4 );
00358    //cout << " remove hole: 0x" << hex << bits << " -> 0x" << bitstmp << dec 
00359    //     << endl;
00360    bits = bitstmp;
00361 
00362    plane =    (bits >>  9) & mask10;
00363    //Int_t tmp   =    (bits >>  8) & mask1;
00364    //end   = (StripEnd::StripEnd_t)tmp;
00365    end = ((bits>>8)&mask1) ? StripEnd::kNegative : StripEnd::kPositive;
00366    pixel =     bits        & mask8;
00367 }
00368 
00369 //_____________________________________________________________________________
00370 void PlexusReroot::BuildPixelMaps(const VldContext& /* vldc */) const
00371 { 
00372    // build the basic maps   RawChannel <--> PixeSpot <--> StripEnd
00373 
00374    MSG("Plex",Msg::kInfo) << "PlexusReroot::BuildPixelMaps " << endl;
00375    fVldRange.Print();
00376    return;
00377 }
00378 
00379 //_____________________________________________________________________________
00380 void PlexusReroot::BuildReadoutMap(const VldContext& /* vldc */) const
00381 { 
00382    // build the basic map   RawChannel --> ReadoutType
00383 
00384    MSG("Plex",Msg::kInfo) << "PlexusReroot::BuildReadoutMap " << endl;
00385    fVldRange.Print();
00386    return;
00387 }
00388 
00389 //_____________________________________________________________________________
00390 void PlexusReroot::BuildPinDiodeMap(const VldContext& /* vldc */) const
00391 { 
00392    // build the basic maps   RawChannel --> PinDiode
00393 
00394    MSG("Plex",Msg::kInfo) << "PlexusReroot::BuildPinDiodeMap " << endl;
00395    fVldRange.Print();
00396    return;
00397 }
00398 
00399 //_____________________________________________________________________________
00400 

Generated on Mon Feb 15 11:07:23 2010 for loon by  doxygen 1.3.9.1