mEmcPRDFToRawModule.C

Go to the documentation of this file.
00001 #include "mEmcPRDFToRawModule.h"
00002 #include "emcNodeHelper.h"
00003 
00004 #include "dEmcRawDataWrapper.h"
00005 #include "PHNodeIterator.h"
00006 #include "PHCompositeNode.h"
00007 #include "PHDataNode.h"
00008 #include "Event.h"
00009 
00010 #include <iostream>
00011 using namespace std;
00012 
00013 static const int FeeToSoftwareMap[144] = 
00014 { 121, 120, 133, 132,  97,  96, 109, 108, 73, 72, 85, 84,
00015    49,  48,  61,  60,  25,  24,  37,  36,  1,  0, 13, 12,
00016   123, 122, 135, 134,  99,  98, 111, 110, 75, 74, 87, 86,
00017    51,  50,  63,  62,  27,  26,  39,  38,  3,  2, 15, 14,
00018   125, 124, 137, 136, 101, 100, 113, 112, 77, 76, 89, 88,
00019    53,  52,  65,  64,  29,  28,  41,  40,  5,  4, 17, 16,
00020   127, 126, 139, 138, 103, 102, 115, 114, 79, 78, 91, 90,
00021    55,  54,  67,  66,  31,  30,  43,  42,  7,  6, 19, 18,
00022   129, 128, 141, 140, 105, 104, 117, 116, 81, 80, 93, 92,
00023    57,  56,  69,  68,  33,  32,  45,  44,  9,  8, 21, 20,
00024   131, 130, 143, 142, 107, 106, 119, 118, 83, 82, 95, 94,
00025    59,  58,  71,  70,  35,  34,  47,  46, 11, 10, 23, 22
00026 };
00027 
00028 //_____________________________________________________________________________
00029 mEmcPRDFToRawModule::mEmcPRDFToRawModule()
00030 {
00031   name = "mEmcPRDFToRawModule";
00032 }
00033 
00034 PHBoolean
00035 mEmcPRDFToRawModule::event(PHCompositeNode* topNode)
00036 {
00037   PHCompositeNode* emcNode = emcNodeHelper::findCompositeNode(topNode,"EMC");
00038 
00039   if (!emcNode)
00040     {
00041       cerr << __FILE__ << ":" << __LINE__ << " Could not find EMC node !"
00042            << endl;
00043       return false;
00044     }
00045 
00046   dEmcRawDataWrapper* demcraw = 
00047     emcNodeHelper::getTable<dEmcRawDataWrapper>("dEmcRawData",emcNode);
00048 
00049   if (!demcraw)
00050     {
00051       cerr << __FILE__ << ":" << __LINE__ << " Could not find dEmcRawData table !"
00052            << endl;
00053       return false;
00054     }
00055 
00056   PHNodeIterator iter(topNode);
00057   PHNode* n1 = iter.findFirst("PHDataNode", "PRDF");
00058   if ( !n1 )
00059     {
00060       cerr << __FILE__ << ":" << __LINE__ << " Could not find PRDF node ! "
00061            << endl;
00062       return false;
00063     }
00064 
00065   PHDataNode<Event>* eventNode = static_cast<PHDataNode<Event>*>(n1);
00066   Event* event = eventNode->getData();
00067   if (!event)
00068     {
00069       cerr << __FILE__ << ":" << __LINE__ 
00070            << " Could not find Event in PRDF node ! "
00071            << endl;
00072       return false;
00073     }
00074 
00075   // Get the relevant packets from the Event object and transfer the
00076   // data to the subsystem-specific table.
00077   Packet* p;
00078   static const int id_base     = 8000;
00079   static const int max_packets = 172;
00080   short id = 0; // unique identifier of the RAW entry
00081 
00082   for (int ipkt = 1; ipkt <= max_packets; ipkt++)
00083     {
00084       int pktid = id_base + ipkt;
00085 
00086       // get packet
00087       p = event->getPacket(pktid);
00088       if ( p != 0 )
00089         {
00090           // go through all channels, save those that have a hit
00091           for (int ifemch=0; ifemch<144; ifemch++)
00092             {
00093               // check if there is a hit (ie, if all data values are 0)
00094               if ( (p->iValue(ifemch, 0) + p->iValue(ifemch, 0) + p->iValue(ifemch, 0) +
00095                     p->iValue(ifemch, 0) + p->iValue(ifemch, 0)) == 0 )
00096                 {
00097                   continue;
00098                 }
00099 
00100               // now get the swkey and detector type (hwkey is not used?)
00101               short detector_type = -1;
00102               int arm, sector, iy, iz;
00103               int swkey = -1;
00104               int module = p->iValue(0, "MODULE");
00105               if (module != ipkt)
00106                 {
00107                   cout << "mEmcPRDFToRaw: error, FEM and packetid mismatch" << endl;
00108                 }
00109 
00110               // module number from packet should always match packetid-8000, but if not
00111               // we use the packetid as the correct identity
00112               if (ipkt <= 72)
00113                 {
00114                   arm = 0;
00115                   sector = (ipkt-1)/18;
00116                 }
00117               else
00118                 {
00119                   arm = 1;
00120                   if (ipkt <= 108)
00121                     {
00122                       sector = (ipkt-73)/18 + 2;
00123                       iy = ((ipkt-(sector*18)-1)/6)*12 + FeeToSoftwareMap[ifemch]/12;
00124                       iz = ((ipkt-(sector*18)-1)%6)*12 + FeeToSoftwareMap[ifemch]%12;
00125                     }
00126                   else             sector = (ipkt-109)/32;
00127                 }
00128 
00129               if (ipkt <= 108)
00130                 {
00131                   iy = ( ((ipkt-1)%18)/6 )*12 + FeeToSoftwareMap[ifemch]/12;
00132                   iz = ((ipkt - 1)%6)*12 + FeeToSoftwareMap[ifemch]%12;
00133                 }
00134               else
00135                 {
00136                   iy = ( ((ipkt-109)%32)/8 )*12 + FeeToSoftwareMap[ifemch]/12;
00137                   iz = ((ipkt - 109)%8)*12 + FeeToSoftwareMap[ifemch]%12;
00138                 }
00139 
00140               swkey = arm*100000 + sector*10000 + iy*100 + iz;
00141 
00142               if (ipkt < 109) detector_type = 1;        // PbSc
00143               else            detector_type = 2;        // PbGl
00144 
00145               demcraw->set_id(id, id+1);        // starts counting at 1
00146               demcraw->set_evno(id, p->iValue(0,"EVTNR") );
00147               demcraw->set_hwkey(id, 0);
00148               demcraw->set_swkey(id, swkey);
00149               demcraw->set_type(id, detector_type);
00150               demcraw->set_adclopre(id,  p->iValue(ifemch, 3) ^ 0xfff );
00151               demcraw->set_adclopost(id, p->iValue(ifemch, 1) ^ 0xfff );
00152               demcraw->set_adchipre(id,  p->iValue(ifemch, 4) ^ 0xfff );
00153               demcraw->set_adchipost(id, p->iValue(ifemch, 2) ^ 0xfff );
00154               demcraw->set_tdc(id,       p->iValue(ifemch, 0) ^ 0xfff );
00155 
00156               id++;
00157             }
00158 
00159           delete p;     // free the sucker
00160         }
00161 
00162     }
00163 
00164   demcraw->SetRowCount( id );
00165 
00166   return 0;  
00167 }