Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:16

0001 #include "HistoManager.h"
0002 #include "TProfile.h"
0003 #include <iostream>
0004 
0005 HistoManager::HistoManager(TDirectory* parent)
0006 {
0007   pedHistDir   = (TDirectory*)parent->Get("PEDESTAL");
0008   ledHistDir   = (TDirectory*)parent->Get("LED");
0009   laserHistDir = (TDirectory*)parent->Get("LASER");
0010   beamHistDir  = (TDirectory*)parent->Get("BEAM");
0011   otherHistDir = (TDirectory*)parent->Get("OTHER");
0012 }
0013 
0014 std::string HistoManager::nameForFlavor(HistType ht)
0015 {
0016   switch (ht) {
0017   case(ENERGY) : return "Energy"; break;
0018   case(TIME)   : return "Time";   break;
0019   case(PULSE)  : return "Pulse";  break;
0020   case(ADC)    : return "ADC";    break;
0021   default      : return "";       break;
0022   }
0023 }
0024 
0025 std::string HistoManager::nameForEvent(EventType et)
0026 {
0027   switch(et) {
0028   case(PEDESTAL) : return "Pedestal"; break;
0029   case(LED)      : return "LED";      break;
0030   case(LASER)    : return "Laser";    break;
0031   case(BEAM)     : return "Beam";     break;
0032   default        : return "Other";    break;
0033   } 
0034 }
0035 
0036 TH1* HistoManager::GetAHistogram(const MyHcalDetId& id,
0037                  HistType ht,
0038                  EventType et)
0039 {
0040   std::string flavor=nameForFlavor(ht);
0041   TDirectory* td;
0042 
0043   switch (et) {
0044   case(PEDESTAL) : td=pedHistDir;   break;
0045   case(LED)      : td=ledHistDir;   break;
0046   case(LASER)    : td=laserHistDir; break;
0047   case(BEAM)     : td=beamHistDir;  break;
0048   case(UNKNOWN)  : td=otherHistDir; break;
0049   default        : td=0;            break;
0050   }
0051 
0052   if (!td) {
0053     printf("Event type not known, et=%d\n", et);
0054     return 0;
0055   }
0056 
0057   char name[120];
0058 
0059   std::string subdetStr;
0060   switch (id.subdet) {
0061   case (HcalBarrel)  : subdetStr="HB"; break;
0062   case (HcalEndcap)  : subdetStr="HE"; break;
0063   case (HcalOuter)   : subdetStr="HO"; break;
0064   case (HcalForward) : subdetStr="HF"; break;
0065   default            : subdetStr="Other"; break;
0066   }
0067 
0068   TH1* retval=0;
0069   sprintf(name,"%s_%s_%d_%d_%d",
0070       flavor.c_str(),subdetStr.c_str(),id.ieta,id.iphi,id.depth);
0071 
0072   TList* keyList = td->GetListOfKeys();
0073   
0074   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
0075     std::string keyname = keyList->At(keyindex)->GetName();
0076     if (strstr(keyname.c_str(),name)) {
0077       retval=(TH1*)td->Get(keyname.c_str());
0078       break;
0079     }
0080   }
0081 
0082   return retval;
0083 }
0084 
0085 
0086 
0087 
0088 TH1* HistoManager::GetAHistogram(const MyElectronicsId& eid,
0089                  HistType ht,
0090                  EventType et)
0091 {
0092   std::string flavor=nameForFlavor(ht);
0093   TDirectory* td;
0094 
0095   switch (et) {
0096   case(PEDESTAL): td=pedHistDir; break;
0097   case(LED): td=ledHistDir; break;
0098   case(LASER): td=laserHistDir; break;
0099   case(BEAM): td=beamHistDir; break;
0100   case(UNKNOWN): td=otherHistDir; break;
0101   default: td=0; break;
0102   }
0103 
0104   if (td==0) {
0105     printf("Unknown %d !\n", et);
0106     return 0;
0107   }
0108 
0109   char name[120];
0110 
0111 
0112   char topbot;
0113   if (eid.tb==0){topbot = 'b';}
0114   else{topbot='t';}
0115   TH1* retval=0;
0116   sprintf(name,"%d_%d_HTR_%d:%d%c",
0117       eid.fiber, eid.fiberChan, eid.crate, eid.Slot,topbot);
0118   TList* keyList = td->GetListOfKeys();
0119   
0120   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
0121     std::string keyname = keyList->At(keyindex)->GetName();
0122     if ((strstr(keyname.c_str(),name))&&(strstr(keyname.c_str(),flavor.c_str()))) {
0123       retval=(TH1*)td->Get(keyname.c_str());
0124       break;
0125     }
0126   }
0127 
0128   return retval;
0129 }
0130 
0131 
0132 std::vector<MyHcalDetId> HistoManager::getDetIdsForType(HistType ht,
0133                             EventType et)
0134 {
0135   char keyflavor[100];
0136   char keysubDet[100];
0137   MyHcalDetId mydetid;
0138   TDirectory* td;
0139   TList* keyList;
0140   std::vector<MyHcalDetId> retvals;
0141 
0142   std::string flavor=nameForFlavor(ht);
0143 
0144   switch (et) {
0145   case(PEDESTAL) : td=pedHistDir;   break;
0146   case(LED)      : td=ledHistDir;   break;
0147   case(LASER)    : td=laserHistDir; break;
0148   case(BEAM)     : td=beamHistDir;  break;
0149   case(UNKNOWN)  : td=otherHistDir; break;
0150   default        : td=0;            break;
0151   }
0152 
0153   if (!td) {
0154     printf("Event type not known, et=%d\n", et);
0155     return retvals;
0156   }
0157 
0158   keyList = td->GetListOfKeys();
0159   
0160   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
0161     int converted;
0162     std::string keyname = keyList->At(keyindex)->GetName();
0163     // cout << keyindex << " " << keyname << endl;
0164     while (keyname.find("_")!=std::string::npos)
0165       keyname.replace(keyname.find("_"),1," ");
0166     converted = sscanf(keyname.c_str(),"%s %s %d %d %d",
0167                keyflavor,keysubDet,
0168                &mydetid.ieta,&mydetid.iphi,&mydetid.depth);
0169     if( (flavor==keyflavor) && (converted==5) ) {
0170       if (!strcmp(keysubDet,"HB")) mydetid.subdet=HcalBarrel;
0171       else if (!strcmp(keysubDet,"HE")) mydetid.subdet=HcalEndcap;
0172       else if (!strcmp(keysubDet,"HO")) mydetid.subdet=HcalOuter;
0173       else if (!strcmp(keysubDet,"HF")) mydetid.subdet=HcalForward;
0174       else continue; // and do not include this in the list!
0175 
0176       retvals.push_back(mydetid);
0177     }
0178   }
0179 
0180 
0181   return retvals;
0182 }
0183 
0184 
0185 std::vector<MyElectronicsId> HistoManager::getElecIdsForType(HistType ht,
0186                             EventType et)
0187 {
0188   char keyflavor[100];
0189   char keysubDet[100];
0190   MyElectronicsId mydeteid;
0191   TDirectory* td;
0192   TList* keyList;
0193   std::vector<MyElectronicsId> retvals;
0194 
0195   std::string flavor=nameForFlavor(ht);
0196 
0197   switch (et) {
0198   case(PEDESTAL): td=pedHistDir; break;
0199   case(LED): td=ledHistDir; break;
0200   case(LASER): td=laserHistDir; break;
0201   case(BEAM): td=beamHistDir; break;
0202   case(UNKNOWN): td=otherHistDir; break;
0203   default: td=0; break;
0204   }
0205   if (!td) {
0206     printf("Event type not known, et=%d\n", et);
0207     return retvals;
0208   }
0209 
0210   keyList = td->GetListOfKeys();
0211   if (keyList==0) return retvals;
0212   
0213   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
0214     int converted;
0215     std::string keyname = keyList->At(keyindex)->GetName();
0216     while (keyname.find("_")!=std::string::npos)
0217       keyname.replace(keyname.find("_"),1," ");
0218     char bottop;
0219     
0220     //printf("%s\n",keyname.c_str());
0221  
0222     if(strstr(keyname.c_str(),"CALIB")){
0223        converted = sscanf(keyname.c_str(),"%s %*s %s %*d %*d chan=%*s eid=%*d %*d %d %d HTR %d:%d%c ",
0224               keyflavor,keysubDet, &mydeteid.fiber,&mydeteid.fiberChan,&mydeteid.crate,&mydeteid.Slot,&bottop);
0225             
0226    if (bottop=='t')
0227       {mydeteid.tb=1;}
0228     else
0229       {mydeteid.tb=0;} 
0230 
0231    // printf("%d converts to %d %d %d %d %c\n",converted,mydeteid.fiber,mydeteid.fiberChan,mydeteid.crate,mydeteid.Slot,bottop);
0232 
0233     }else{
0234       converted = sscanf(keyname.c_str(),"%s %s %*d %*d %*d eid=%*d %*d %d %d HTR %d:%d%c ",
0235              keyflavor,keysubDet, &mydeteid.fiber,&mydeteid.fiberChan,&mydeteid.crate,&mydeteid.Slot,&bottop);
0236       
0237         
0238     if (bottop=='t')
0239       {mydeteid.tb=1;}
0240     else
0241       {mydeteid.tb=0;}
0242     }
0243     //printf("converts to %d %d %d %d %d\n",mydeteid.fiber,mydeteid.fiberChan,mydeteid.crate,mydeteid.Slot,mydeteid.tb);
0244 
0245 
0246     if( (flavor==keyflavor) && (converted==7) )
0247 
0248       retvals.push_back(mydeteid);
0249     
0250   }
0251 
0252   
0253   return retvals;
0254 }
0255 
0256